#include <bits/stdc++.h>
using namespace std;

#define N 100010
int n, k;
vector<int> g[N];

bool vis[N];
int dist[N];
int bfs(int u) {
  memset(vis, 0, sizeof vis);
  memset(dist, 0, sizeof dist);

  queue<int> q;

  dist[u] = 0; vis[u] = true;
  q.push(u);

  int v;
  while (!q.empty()) {
    v = q.front(); q.pop();
    for (int w : g[v]) {
      if (!vis[w]) {
        vis[w] = true;
        dist[w] = dist[v] + 1;
        q.push(w);
      }
    }
  }

  return v;
}

int main() {
  scanf("%d %d", &n, &k);
  for (int i = 1; i < n; i++) {
    int u, v; scanf("%d %d", &u, &v);
    g[u].push_back(v);
    g[v].push_back(u);
  }
  bool ok = true;
  for (int u = 1; u <= n; u++) {
    ok &= g[u].size() != 2;
  }
  printf("%s\n", (ok && dist[bfs(bfs(1))] <= 2 * k) ? "Yes" : "No");
}


#include <bits/stdc++.h>
using namespace std;

#define N 100010
int n, k;
vector<int> g[N];

bool vis[N];
int dist[N], par[N];
bool solve() {
  queue<int> q;

  for (int u = 1; u <= n; u++) {
    if (g[u].size() == 1) {
      dist[u] = 0; vis[u] = true; par[u] = -1;
      q.push(u);
    }
  }

  while (!q.empty()) {
    int v = q.front(); q.pop();
    for (int w : g[v]) {
      if (!vis[w]) {
        vis[w] = true;
        dist[w] = dist[v] + 1;
        par[w] = v;
        q.push(w);
      }
    }
  }

  //printf("%d\n", *max_element(dist + 1, dist + n + 1));
  bool ok = *max_element(dist + 1, dist + n + 1) == k;
  for (int u = 1; u <= n; u++) {
    for (int v : g[u]) {
      ok &= dist[v] == dist[u] + 1 || dist[u] == dist[v] + 1;
      /*if (!ok) {
        printf("%d %d | %d %d\n", u, v, dist[u], dist[v]);
      }*/
    }
  }

  return ok;
}

int main() {
  scanf("%d %d", &n, &k);
  for (int i = 1; i < n; i++) {
    int u, v; scanf("%d %d", &u, &v);
    g[u].push_back(v);
    g[v].push_back(u);
  }
  bool ok = true;
  for (int u = 1; u <= n; u++) {
    ok &= g[u].size() != 2;
  }
  printf("%s\n", ok && solve() ? "Yes" : "No");
}


#include <bits/stdc++.h>
using namespace std;

#define N 100010
int n, k;
vector<int> g[N];

bool vis[N];
int dist[N], par[N];
bool solve() {
  queue<int> q;

  for (int u = 1; u <= n; u++) {
    if (g[u].size() == 1) {
      dist[u] = 0; vis[u] = true; par[u] = -1;
      q.push(u);
    }
  }

  while (!q.empty()) {
    int v = q.front(); q.pop();
    for (int w : g[v]) {
      if (!vis[w]) {
        vis[w] = true;
        dist[w] = dist[v] + 1;
        par[w] = v;
        q.push(w);
      }
    }
  }

  //printf("%d\n", *max_element(dist + 1, dist + n + 1));
  bool ok = *max_element(dist + 1, dist + n + 1) == k;
  for (int u = 1; u <= n; u++) {
    if (dist[u] != k) {
      ok &= g[u].size() > 3 || g[u].size() == 1;
    }
    for (int v : g[u]) {
      ok &= dist[v] == dist[u] + 1 || dist[u] == dist[v] + 1;
      /*if (!ok) {
        printf("%d %d | %d %d\n", u, v, dist[u], dist[v]);
      }*/
    }
  }

  if (!ok) return false;
  int count = 0;
  for (int u = 1; u <= n; u++) {
    if (dist[u] == k) count++;
  }
  assert(count == 1);
  return true;
}

int main() {
  scanf("%d %d", &n, &k);
  for (int i = 1; i < n; i++) {
    int u, v; scanf("%d %d", &u, &v);
    g[u].push_back(v);
    g[v].push_back(u);
  }
  bool ok = true;
  for (int u = 1; u <= n; u++) {
    ok &= g[u].size() != 2;
  }
  printf("%s\n", ok && solve() ? "Yes" : "No");
}


//package cf;
import java.io.*;
import java.util.*;
public class phno {
    static int p=1000000007;
    public static void main(String[] args) throws Exception{
        BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(java.io.FileDescriptor.out), "ASCII"), 512);
        FastReader sc=new FastReader();

        StringBuilder sb=new StringBuilder();
        int n = sc.nextInt();
        int k = sc.nextInt();
        int ar[]=new int[n/k];
        int br[]=new int[n/k];
        for(int i=0;i<n/k;i++)
            ar[i]=sc.nextInt();

        for(int i=0;i<n/k;i++)
            br[i]=sc.nextInt();

        ///fnds
        long dg=(long)pow(10,k,p)-1;
       // System.out.println(dg);
        long res=1;
        for(int i=0;i<n/k;i++)
        {
            long tot=dg/ar[i];
           // System.out.println(tot);
            if(br[i]>0)
            tot++;
             //if(br[i]!=0) {
                 long ndg = (dg + 1);
                // if(br[i]>0)
                 tot -= ((ndg * (br[i] + 1) / 10) - 1) / ar[i] - ((ndg * (br[i]) / 10 - 1)<0?0:(ndg * (br[i]) / 10 - 1)) / ar[i];

           ///  System.out.println(tot);//((ndg*(br[i]+1)/10)-1)/ar[i]);
            res=(res%p*tot%p)%p;
        }
        sb.append(res);
        out.write(sb.toString());
        out.flush();
    }

    public static long pow(long a,long b,long m)
    {
        long r=1;
        while(b!=1)
        {
            if(b%2!=0)
                r=(r*a)%m;
            b=b>>1;
            a=(a*a)%m;
        }
        return (r*a)%m;
    }

    ///////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
    static class FastReader {

        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

}


//package cf;
import java.io.*;
import java.util.*;
public class phno {
    static int p=1000000007;
    public static void main(String[] args) throws Exception{
        BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(java.io.FileDescriptor.out), "ASCII"), 512);
        FastReader sc=new FastReader();

        StringBuilder sb=new StringBuilder();
        int n = sc.nextInt();
        int k = sc.nextInt();
        int ar[]=new int[n/k];
        int br[]=new int[n/k];
        for(int i=0;i<n/k;i++)
            ar[i]=sc.nextInt();

        for(int i=0;i<n/k;i++)
            br[i]=sc.nextInt();

        long dg=(long)pow(10,k,p)-1;
       // System.out.println(dg);
        long res=1;
        for(int i=0;i<n/k;i++)
        {
            long tot=dg/ar[i];
           // System.out.println(tot);
            if(br[i]>0)
            tot++;
             //if(br[i]!=0) {
                 long ndg = (dg + 1);
                // if(br[i]>0)
                 tot -= ((ndg * (br[i] + 1) / 10) - 1) / ar[i] - ((ndg * (br[i]) / 10 - 1)<0?0:(ndg * (br[i]) / 10 - 1)) / ar[i];

           ///  System.out.println(tot);//((ndg*(br[i]+1)/10)-1)/ar[i]);
            res=(res%p*tot%p)%p;
        }
        sb.append(res);
        out.write(sb.toString());
        out.flush();
    }

    public static long pow(long a,long b,long m)
    {
        long r=1;
        while(b!=1)
        {
            if(b%2!=0)
                r=(r*a)%m;
            b=b>>1;
            a=(a*a)%m;
        }
        return (r*a)%m;
    }

    ///////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
    static class FastReader {

        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

}


//package cf;
import java.io.*;
import java.util.*;
public class phno {
    static int p=1000000007;
    public static void main(String[] args) throws Exception{
        BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(java.io.FileDescriptor.out), "ASCII"), 512);
        FastReader sc=new FastReader();

        StringBuilder sb=new StringBuilder();
        int n = sc.nextInt();
        int k = sc.nextInt();
        int ar[]=new int[n/k];
        int br[]=new int[n/k];
        for(int i=0;i<n/k;i++)
            ar[i]=sc.nextInt();

        for(int i=0;i<n/k;i++)
            br[i]=sc.nextInt();

        long dg=(long)pow(10,k,p)-1;
       // System.out.println(dg);
        long res=1;
        for(int i=0;i<n/k;i++)
        {
            long tot=dg/ar[i];
           // System.out.println(tot);
            tot++;
               long ndg = (dg +1);

                tot-=((ndg*(br[i]+1)/10)-1)/ar[i]-(ndg*(br[i])/10-1)/ar[i];
           // System.out.println(((ndg*(br[i]+1)/10)-1)/ar[i]);
            res=(res%p*tot%p)%p;
        }
        sb.append(res);
        out.write(sb.toString());
        out.flush();
    }

    public static long pow(long a,long b,long m)
    {
        long r=1;
        while(b!=1)
        {
            if(b%2!=0)
                r=(r*a)%m;
            b=b>>1;
            a=(a*a)%m;
        }
        return (r*a)%m;
    }

    ///////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
    static class FastReader {

        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

}


//package cf;
import java.io.*;
import java.util.*;
public class phno {
    static int p=1000000007;
    public static void main(String[] args) throws Exception{
        BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(java.io.FileDescriptor.out), "ASCII"), 512);
        FastReader sc=new FastReader();

        StringBuilder sb=new StringBuilder();
        int n = sc.nextInt();
        int k = sc.nextInt();
        int ar[]=new int[n/k];
        int br[]=new int[n/k];
        for(int i=0;i<n/k;i++)
            ar[i]=sc.nextInt();

        for(int i=0;i<n/k;i++)
            br[i]=sc.nextInt();

        long dg=(long)pow(10,k,p)-1;
       // System.out.println(dg);
        long res=1;
        for(int i=0;i<n/k;i++)
        {
            long tot=dg/ar[i];
           // System.out.println(tot);
            if(br[i]>0)
            tot++;
             if(br[i]!=0) {
                 long ndg = (dg + 1);
                // if(br[i]>0)
                 tot -= ((ndg * (br[i] + 1) / 10) - 1) / ar[i] - (ndg * (br[i]) / 10 - 1) / ar[i];
             }
           ///  System.out.println(tot);//((ndg*(br[i]+1)/10)-1)/ar[i]);
            res=(res%p*tot%p)%p;
        }
        sb.append(res);
        out.write(sb.toString());
        out.flush();
    }

    public static long pow(long a,long b,long m)
    {
        long r=1;
        while(b!=1)
        {
            if(b%2!=0)
                r=(r*a)%m;
            b=b>>1;
            a=(a*a)%m;
        }
        return (r*a)%m;
    }

    ///////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
    static class FastReader {

        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

}


//package cf;
import java.io.*;
import java.util.*;
public class phno {
    static int p=1000000007;
    public static void main(String[] args) throws Exception{
        BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(java.io.FileDescriptor.out), "ASCII"), 512);
        FastReader sc=new FastReader();

        StringBuilder sb=new StringBuilder();
        int n = sc.nextInt();
        int k = sc.nextInt();
        int ar[]=new int[n/k];
        int br[]=new int[n/k];
        for(int i=0;i<n/k;i++)
            ar[i]=sc.nextInt();

        for(int i=0;i<n/k;i++)
            br[i]=sc.nextInt();

        long dg=(long)pow(10,k,p)-1;
       // System.out.println(dg);
        long res=1;
        for(int i=0;i<n/k;i++)
        {
            long tot=dg/ar[i];
           // System.out.println(tot);
            tot++;
            if((long)Math.log10(ar[i])==(long)Math.log10(dg))
            {
                long df=(((dg+1)*br[i])/10)%ar[i];
                df=df>dg/10?ar[i]-df:df;
                if(df<=dg/10)
                    tot--;
              // System.out.println(df+" ][");
            }
            else {
                long ndg = dg / 10;
                tot -= ndg / ar[i];
                if ((((dg + 1) * br[i]) / 10) % ar[i] == 0)
                    tot--;
            }
           // System.out.println(tot);
            res=(res%p*tot%p)%p;
        }
        sb.append(res);
        out.write(sb.toString());
        out.flush();
    }

    public static long pow(long a,long b,long m)
    {
        long r=1;
        while(b!=1)
        {
            if(b%2!=0)
                r=(r*a)%m;
            b=b>>1;
            a=(a*a)%m;
        }
        return (r*a)%m;
    }

    ///////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
    static class FastReader {

        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

}


//package cf;
import java.io.*;
import java.util.*;
public class phno {
    static int p=1000000007;
    public static void main(String[] args) throws Exception{
        BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(java.io.FileDescriptor.out), "ASCII"), 512);
        FastReader sc=new FastReader();

        StringBuilder sb=new StringBuilder();
        int n = sc.nextInt();
        int k = sc.nextInt();
        int ar[]=new int[n/k];
        int br[]=new int[n/k];
        for(int i=0;i<n/k;i++)
            ar[i]=sc.nextInt();

        for(int i=0;i<n/k;i++)
            br[i]=sc.nextInt();

        long dg=(long)pow(10,k,p)-1;
       // System.out.println(dg);
        long res=1;
        for(int i=0;i<n/k;i++)
        {
            long tot=dg/ar[i];
           // System.out.println(tot);
            tot++;
            if((long)Math.log10(ar[i])==(long)Math.log10(dg))
            {
                long df=(((dg+1)*br[i])/10)/ar[i];
                df++;
                df=df*ar[i];
                if(df<=((dg+1)*(br[i]+1)/10)-1)
                {
                    tot--;
                }
               // System.out.println((dg+1)*(br[i]+1)/10+" ][");
            }
            else {
                long ndg = dg / 10;
                tot -= ndg / ar[i];
                if ((((dg + 1) * br[i]) / 10) % ar[i] == 0)
                    tot--;
            }
           // System.out.println(tot);
            res=(res%p*tot%p)%p;
        }
        sb.append(res);
        out.write(sb.toString());
        out.flush();
    }

    public static long pow(long a,long b,long m)
    {
        long r=1;
        while(b!=1)
        {
            if(b%2!=0)
                r=(r*a)%m;
            b=b>>1;
            a=(a*a)%m;
        }
        return (r*a)%m;
    }

    ///////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
    static class FastReader {

        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

}


//package cf;
import java.io.*;
import java.util.*;
public class phno {
    static int p=1000000007;
    public static void main(String[] args) throws Exception{
        BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(java.io.FileDescriptor.out), "ASCII"), 512);
        FastReader sc=new FastReader();

        StringBuilder sb=new StringBuilder();
        int n = sc.nextInt();
        int k = sc.nextInt();
        int ar[]=new int[n/k];
        int br[]=new int[n/k];
        for(int i=0;i<n/k;i++)
            ar[i]=sc.nextInt();

        for(int i=0;i<n/k;i++)
            br[i]=sc.nextInt();

        long dg=(long)pow(10,k,p)-1;
       // System.out.println(dg);
        long res=1;
        for(int i=0;i<n/k;i++)
        {
            long tot=dg/ar[i];
           // System.out.println(tot);
            if(br[i]!=0)
            tot++;
               long ndg = (dg +1);
               // if(br[i]>0)
                tot-=((ndg*(br[i]+1)/10)-1)/ar[i]-(ndg*(br[i])/10-1)/ar[i];
         //   System.out.println(tot);//((ndg*(br[i]+1)/10)-1)/ar[i]);
            res=(res%p*tot%p)%p;
        }
        sb.append(res);
        out.write(sb.toString());
        out.flush();
    }

    public static long pow(long a,long b,long m)
    {
        long r=1;
        while(b!=1)
        {
            if(b%2!=0)
                r=(r*a)%m;
            b=b>>1;
            a=(a*a)%m;
        }
        return (r*a)%m;
    }

    ///////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
    static class FastReader {

        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

}


                              //ABHISHEK AGRAWAL,BIT mesra//
                      //Newbie......You have to be odd to be no. ONE :)//
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define fl float
#define lcm(a,b) (a*(b/__gcd(a,b)))
#define vs vector <string>
#define vc vector <char>
#define vii vector<int>
#define vll vector<ll>
#define sll set<ll>
#define pii pair<int,int>
#define plc pair<ll,char>
#define tlll tuple<ll,ll,ll>
#define mt make_tuple
#define vpll vector<pair<ll,ll>>
#define vpii vector<pair<int,int>>
#define vtll vector<tuple<ll,ll,ll>>
#define vvll vector<vector<ll>>
#define lb lower_bound
#define pb push_back
#define pob pop_back
#define f first
#define s second
#define mll map<ll,ll>
#define mp make_pair
#define sp(n) fixed<<setprecision(n)
#define mcl map<char,ll>
#define msl map<string,ll>
#define mod (ll)1000000007
#define flash ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define test ll t;read(t);while(t--)
#define sortv(v) sort(v.begin(),v.end())
#define INF (ll)(1e15)
#define loop(i,n) for(int i=0;i<n;i++)
#define loop1(i,n) for(int i=1;i<=n;i++)
#define rloop(n,i) for(int i=n-1;i>=0;i--)
#define loopab(i,a,b,c) for(int i=a;i<=b;i+=c)
#define reada(a,n) loop(i,n) cin>>a[i];
#define reada1(a,n) loop1(i,n) cin>>a[i];
#define sorta(a) sort(a,a+n,greater<ll>())
#define countone(n) __builtin_popcount(n)
#define numoftrailzero(n) __builtin_ctz(n)
#define maxpowoftwo(n) __builtin_clz(n)
#define leastindexwithone(n)  __builtin_ffs(n)
#define what_is(x) cerr << #x << " is " << x << endl;
#define pfv(v) cout<<v.size()<<"\n";loop(i,v.size()) cout<<v[i]<<" ";cout<<"\n";
#define pv(v) loop(i,v.size()) cout<<v[i]<<" ";
#define all(v) v.begin(),v.end()
#define mset(dp,val) memset(dp,val,sizeof(dp))
//if we need to devide any given number in powers of term the power of max term
#define answer(n) ceil(log2(n+1))
unsigned ll q,n;ll sum,ans;
// ll gcd(ll a, ll b){if (b==0){return a;} return gcd(b,a%b);}
ll powe(ll a,ll b){ll res=1;while(b>0){if(b%2 ==1){res=(res*a);}a=(a*a);b/=2;} return res;}
// ll power(ll a,ll b,ll M){a%=M;ll res=1;while(b>0){if(b%2 ==1){res=(res*a)%M;}a=(a*a)%M;b/=2;} return res;}
ll extendedEuclid(ll A,ll B,ll &x,ll &y){
    if(B == 0) {
        x = 1;
        y = 0;
        return A;
    }
    else {
        ll x1 , y1;
        ll gcd = extendedEuclid(B,A%B,x1,y1);
        y = x1-(A/B)*y1;
        x = y1;
        return gcd;
    }
}
ll mi(ll A, ll M){ll x,y;extendedEuclid(A,M,x,y);if(x<0){x+=M;} return x;}
// vector<bool>sieve(1000000,true);
// void Sieve(){
//  sieve[0]=false;
//  sieve[1]=false;
//  for(ll i=2;i*i<=1000000;i++){
//   if(sieve[i]==true){
//    for(ll j=i*i;j<1000000;j+=i)
//     sieve[j]=false;
//   }
//  }
// }
//  vll sieve_spf;
// void Sieve_spf(){
//  const ll n = 1e6 + 5;
//  sieve_spf.resize(n);

//  loop(i,n)
//   sieve_spf[i]=i;

//  sieve_spf[0]=-1;
//  sieve_spf[1]=1;

//  loopab(i,2,n,2)
//   sieve_spf[i]=2;

//  loopab(i,3,n,2)
//   if(sieve_spf[i]==i)
//    loopab(j,i*i,n,i)
//     if(sieve_spf[j]==j)
//      sieve_spf[j]=i;
// }
// #ifdef TESTING
// #define DEBUG fprintf(stderr, "====TESTING====\n")
// #define VALUE(x) cerr << "The value of " << #x << " is " << x << endl
// #define debug(...) fprintf(stderr, __VA_ARGS__)
// #else
// #define DEBUG
// #define VALUE(x)
// #define debug(...)
// #endif
// bool isUpcase(char c){
//     if(c >= 'A'&&c <= 'Z') return true;
//     else return false;
// }
// bool islowcase(char c){
//     if(c >= 'a'&&c <= 'z') return true;
//     else return false;
// }
const int nax=3e5+5;
ll fact[nax];
void F(){
 fact[0]=1;
 for(int i=1;i<nax;i++){
  fact[i]=fact[i-1]*i%mod;
 }
}
ll nCr(ll n,ll r,ll M){
 if(n<r)return 0;
 return (((fact[n]*mi(fact[r],M))%M)*mi(fact[n-r]%M,M))%M;
}
void the_happiest_place_on_earth()
{
    flash;
  #ifdef ENABLE_FILE_IO
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
  #endif
}
bool comp(const pair<ll,ll> &a, const pair<ll,ll> &b){
 if(a.f<b.f||a.f==b.f&&a.s>b.s)
  return true;
 else
  return false;
}

const int N=300055;ll a[N],b[N];
void testcase(){
  int k;
  cin>>n>>k;
  loop(i,n/k) cin>>a[i];
  loop(i,n/k) cin>>b[i];
  ans=1;
  loop(i,n/k){
    ll p=0;
    loop(d,10){
      if(d!=b[i]){
        ll d1=d,maxv=d;
        loop1(i,k-1) maxv=maxv*10+9,d1=d1*10;
        (p+=(maxv/a[i]-d1/a[i]+(d1%a[i]==0))%mod)%mod;
      }
    }
    ans=ans*p%mod;
  }
  cout<<ans%mod<<"\n";
  return;
}

int main(){
  // //the_happiest_place_on_earth;
  // //Today's thought: Push yourself,because no one else is going to do it for you.
  // //Things aren’t always #000000 and #FFFFFF
  // //START OF PROGRAM LOGIC
  // //g++ -o a BB.cpp -DENABLE_FILE_IO;./a
  the_happiest_place_on_earth();
  q=1;//int t=0;
  //cin>>q;
  while(q--){
    //cout<<"Case #"<<++t<<": ";
    testcase();
  }
  // cerr << "Time : " << 1000 *((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
  // //END OF PROGRAM LOGIC

	return 0;
}
/*
######  ###### #     # ####### #     # ##### #     #    #    ####### ####### ######
#     # #      ##    # #     # ##   ##   #   ##    #   # #      #    #     # #     #
#     # #      # #   # #     # # # # #   #   # #   #  #   #     #    #     # #     #
#     # #####  #  #  # #     # #  #  #   #   #  #  # #     #    #    #     # ######
#     # #      #   # # #     # #     #   #   #   # # #######    #    #     # #   #
#     # #      #    ## #     # #     #   #   #    ## #     #    #    #     # #    #
######  ###### #     # ####### #     # ##### #     # #     #    #    ####### #     #
*/


                              //ABHISHEK AGRAWAL,BIT mesra//
                      //Newbie......You have to be odd to be no. ONE :)//
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define fl float
#define lcm(a,b) (a*(b/__gcd(a,b)))
#define vs vector <string>
#define vc vector <char>
#define vii vector<int>
#define vll vector<ll>
#define sll set<ll>
#define pii pair<int,int>
#define plc pair<ll,char>
#define tlll tuple<ll,ll,ll>
#define mt make_tuple
#define vpll vector<pair<ll,ll>>
#define vpii vector<pair<int,int>>
#define vtll vector<tuple<ll,ll,ll>>
#define vvll vector<vector<ll>>
#define lb lower_bound
#define pb push_back
#define pob pop_back
#define f first
#define s second
#define mll map<ll,ll>
#define mp make_pair
#define sp(n) fixed<<setprecision(n)
#define mcl map<char,ll>
#define msl map<string,ll>
#define mod (ll)998244353
#define flash ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define test ll t;read(t);while(t--)
#define sortv(v) sort(v.begin(),v.end())
#define INF (ll)(1e15)
#define loop(i,n) for(int i=0;i<n;i++)
#define loop1(i,n) for(int i=1;i<=n;i++)
#define rloop(n,i) for(int i=n-1;i>=0;i--)
#define loopab(i,a,b,c) for(int i=a;i<=b;i+=c)
#define reada(a,n) loop(i,n) cin>>a[i];
#define reada1(a,n) loop1(i,n) cin>>a[i];
#define sorta(a) sort(a,a+n,greater<ll>())
#define countone(n) __builtin_popcount(n)
#define numoftrailzero(n) __builtin_ctz(n)
#define maxpowoftwo(n) __builtin_clz(n)
#define leastindexwithone(n)  __builtin_ffs(n)
#define what_is(x) cerr << #x << " is " << x << endl;
#define pfv(v) cout<<v.size()<<"\n";loop(i,v.size()) cout<<v[i]<<" ";cout<<"\n";
#define pv(v) loop(i,v.size()) cout<<v[i]<<" ";
#define all(v) v.begin(),v.end()
#define mset(dp,val) memset(dp,val,sizeof(dp))
//if we need to devide any given number in powers of term the power of max term
#define answer(n) ceil(log2(n+1))
unsigned ll q,n;ll sum,ans;
// ll gcd(ll a, ll b){if (b==0){return a;} return gcd(b,a%b);}
ll powe(ll a,ll b){ll res=1;while(b>0){if(b%2 ==1){res=(res*a);}a=(a*a);b/=2;} return res;}
// ll power(ll a,ll b,ll M){a%=M;ll res=1;while(b>0){if(b%2 ==1){res=(res*a)%M;}a=(a*a)%M;b/=2;} return res;}
ll extendedEuclid(ll A,ll B,ll &x,ll &y){
    if(B == 0) {
        x = 1;
        y = 0;
        return A;
    }
    else {
        ll x1 , y1;
        ll gcd = extendedEuclid(B,A%B,x1,y1);
        y = x1-(A/B)*y1;
        x = y1;
        return gcd;
    }
}
ll mi(ll A, ll M){ll x,y;extendedEuclid(A,M,x,y);if(x<0){x+=M;} return x;}
// vector<bool>sieve(1000000,true);
// void Sieve(){
//  sieve[0]=false;
//  sieve[1]=false;
//  for(ll i=2;i*i<=1000000;i++){
//   if(sieve[i]==true){
//    for(ll j=i*i;j<1000000;j+=i)
//     sieve[j]=false;
//   }
//  }
// }
//  vll sieve_spf;
// void Sieve_spf(){
//  const ll n = 1e6 + 5;
//  sieve_spf.resize(n);

//  loop(i,n)
//   sieve_spf[i]=i;

//  sieve_spf[0]=-1;
//  sieve_spf[1]=1;

//  loopab(i,2,n,2)
//   sieve_spf[i]=2;

//  loopab(i,3,n,2)
//   if(sieve_spf[i]==i)
//    loopab(j,i*i,n,i)
//     if(sieve_spf[j]==j)
//      sieve_spf[j]=i;
// }
// #ifdef TESTING
// #define DEBUG fprintf(stderr, "====TESTING====\n")
// #define VALUE(x) cerr << "The value of " << #x << " is " << x << endl
// #define debug(...) fprintf(stderr, __VA_ARGS__)
// #else
// #define DEBUG
// #define VALUE(x)
// #define debug(...)
// #endif
// bool isUpcase(char c){
//     if(c >= 'A'&&c <= 'Z') return true;
//     else return false;
// }
// bool islowcase(char c){
//     if(c >= 'a'&&c <= 'z') return true;
//     else return false;
// }
const int nax=3e5+5;
ll fact[nax];
void F(){
 fact[0]=1;
 for(int i=1;i<nax;i++){
  fact[i]=fact[i-1]*i%mod;
 }
}
ll nCr(ll n,ll r,ll M){
 if(n<r)return 0;
 return (((fact[n]*mi(fact[r],M))%M)*mi(fact[n-r]%M,M))%M;
}
void the_happiest_place_on_earth()
{
    flash;
  #ifdef ENABLE_FILE_IO
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
  #endif
}
bool comp(const pair<ll,ll> &a, const pair<ll,ll> &b){
 if(a.f<b.f||a.f==b.f&&a.s>b.s)
  return true;
 else
  return false;
}

const int N=300055;ll a[N],b[N];
void testcase(){
  int k;
  cin>>n>>k;
  loop(i,n/k) cin>>a[i];
  loop(i,n/k) cin>>b[i];
  ans=1;
  loop(i,n/k){
    ll p=0;
    loop(d,10){
      if(d!=b[i]){
        ll d1=d,maxv=d;
        loop1(i,k-1) maxv=maxv*10+9,d1=d1*10;
        (p+=(maxv/a[i]-d1/a[i]+(d1%a[i]==0))%mod)%mod;
      }
    }
    ans=ans*p%mod;
  }
  cout<<ans%mod<<"\n";
  return;
}

int main(){
  // //the_happiest_place_on_earth;
  // //Today's thought: Push yourself,because no one else is going to do it for you.
  // //Things aren’t always #000000 and #FFFFFF
  // //START OF PROGRAM LOGIC
  // //g++ -o a BB.cpp -DENABLE_FILE_IO;./a
  the_happiest_place_on_earth();
  q=1;//int t=0;
  //cin>>q;
  while(q--){
    //cout<<"Case #"<<++t<<": ";
    testcase();
  }
  // cerr << "Time : " << 1000 *((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
  // //END OF PROGRAM LOGIC

	return 0;
}
/*
######  ###### #     # ####### #     # ##### #     #    #    ####### ####### ######
#     # #      ##    # #     # ##   ##   #   ##    #   # #      #    #     # #     #
#     # #      # #   # #     # # # # #   #   # #   #  #   #     #    #     # #     #
#     # #####  #  #  # #     # #  #  #   #   #  #  # #     #    #    #     # ######
#     # #      #   # # #     # #     #   #   #   # # #######    #    #     # #   #
#     # #      #    ## #     # #     #   #   #    ## #     #    #    #     # #    #
######  ###### #     # ####### #     # ##### #     # #     #    #    ####### #     #
*/


using namespace std;
#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define repa(i,a,b) for (int i=a; i<=b; i++)
#define repd(i,b,a) for (int i=b; i>=a; i--)
#define endl "\n"
//debugging
#define debug1(a) cout<<#a<<" = "<<(a)<<endl;
#define debug2(a,b) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<endl;
#define debug3(a,b,c) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;
#define debug4(a,b,c,d) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<", "<<#d<<" = "<<(d)<<endl;

const int N = 1e+6+5;
int big = 1e+18+3;
int mod = 1e+9+7;

signed main()
{
    IOS;

    int n,k;
    cin>>n>>k;

    int up = 1;

    repa(i,1,k)
        up*=10;
    up--;

    int jump = up/10;
   // debug2(up,jump);
    int a[k+1],b[k+1];

    repa(i,1,n/k)
        cin>>a[i];

    repa(i,1,n/k)
        cin>>b[i];
    int ans = 1;

    repa(i,1,n/k)
    {
        int noe = up/a[i] + 1;

        int l = b[i]*((up+1)/10);
        int r = l + jump;

        int lowest = (l/a[i])*a[i];
        if (lowest<l)
            lowest+=a[i];
        int highest = (r/a[i])*a[i];

        if (highest>=lowest)
            noe-=(highest/a[i] - lowest/a[i]+1);
       // debug4(i,lowest,highest,noe);

        ans*=noe;
        ans%=mod;
    }

    cout<< ans <<endl;
}


using namespace std;
#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define repa(i,a,b) for (int i=a; i<=b; i++)
#define repd(i,b,a) for (int i=b; i>=a; i--)
#define endl "\n"
//debugging
#define debug1(a) cout<<#a<<" = "<<(a)<<endl;
#define debug2(a,b) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<endl;
#define debug3(a,b,c) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;
#define debug4(a,b,c,d) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<", "<<#d<<" = "<<(d)<<endl;

const int N = 1e+6+5;
int big = 1e+18+3;
int mod = 1e+9+7;

signed main()
{
    IOS;

    int n,k;
    cin>>n>>k;

    int up = 1;

    repa(i,1,k)
        up*=10;
    up--;

    int jump = up/10;
    debug2(up,jump);
    int a[k+1],b[k+1];

    repa(i,1,n/k)
        cin>>a[i];

    repa(i,1,n/k)
        cin>>b[i];
    int ans = 1;

    repa(i,1,n/k)
    {
        int noe = up/a[i] + 1;

        int l = b[i]*((up+1)/10);
        int r = l + jump;

        int lowest = (l/a[i])*a[i];
        if (lowest<l)
            lowest+=a[i];
        int highest = (r/a[i])*a[i];

        if (highest>=lowest)
            noe-=(highest/a[i] - lowest/a[i]+1);
       // debug4(i,lowest,highest,noe);

        ans*=noe;
        ans%=mod;
    }

    cout<< ans <<endl;
}


using namespace std;
#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define repa(i,a,b) for (int i=a; i<=b; i++)
#define repd(i,b,a) for (int i=b; i>=a; i--)
#define endl "\n"
//debugging
#define debug1(a) cout<<#a<<" = "<<(a)<<endl;
#define debug2(a,b) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<endl;
#define debug3(a,b,c) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;
#define debug4(a,b,c,d) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<", "<<#d<<" = "<<(d)<<endl;

const int N = 1e+6+5;
int big = 1e+18+3;
int mod = 1e+9+7;

signed main()
{
    IOS;

    int n,k;
    cin>>n>>k;

    int up = 1;

    repa(i,1,k)
        up*=10;
    up--;

    int jump = up/10;
   // debug2(up,jump);
    int a[n+1],b[n+1];

    repa(i,1,n/k)
        cin>>a[i];

    repa(i,1,n/k)
        cin>>b[i];
    int ans = 1;

    repa(i,1,n/k)
    {
        int noe = up/a[i] + 1;

        int l = b[i]*((up+1)/10);
        int r = l + jump;

        int lowest = (l/a[i])*a[i];
        if (lowest<l)
            lowest+=a[i];
        int highest = (r/a[i])*a[i];

        if (highest>=lowest)
            noe-=(highest/a[i] - lowest/a[i]+1);
       // debug4(i,lowest,highest,noe);

        ans*=noe;
        ans%=mod;
    }

    cout<< ans <<endl;
}


using namespace std;
#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define repa(i,a,b) for (int i=a; i<=b; i++)
#define repd(i,b,a) for (int i=b; i>=a; i--)
#define endl "\n"
//debugging
#define debug1(a) cout<<#a<<" = "<<(a)<<endl;
#define debug2(a,b) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<endl;
#define debug3(a,b,c) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;
#define debug4(a,b,c,d) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<", "<<#d<<" = "<<(d)<<endl;

const int N = 1e+6+5;
int big = 1e+18+3;
int mod = 1e+9+7;

signed main()
{
    IOS;

    int n,k;
    cin>>n>>k;

    int up = 1;

    repa(i,1,k)
        up*=10;
    up--;

    int jump = up/10;
    debug2(up,jump);
    int a[n/k+1],b[n/k+1];

    repa(i,1,n/k)
        cin>>a[i];

    repa(i,1,n/k)
        cin>>b[i];
    int ans = 1;

    repa(i,1,n/k)
    {
        int noe = up/a[i] + 1;

        int l = b[i]*((up+1)/10);
        int r = l + jump;

        int lowest = (l/a[i])*a[i];
        if (lowest<l)
            lowest+=a[i];
        int highest = (r/a[i])*a[i];

        if (highest>=lowest)
            noe-=(highest/a[i] - lowest/a[i]+1);
       // debug4(i,lowest,highest,noe);

        ans*=noe;
        ans%=mod;
    }

    cout<< ans <<endl;
}


#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
using namespace std;
ll N = 1000000007;
ll power(ll k)
{
    if(k==0)
        return 1;
    return 10*power(k-1);
}

ll func(ll k,ll a,ll b)
{
    ll x = power(k-1);
    ll y = x*b;
    ll z = y/a;
    z *= a;
    if(z<y)
        z += a;
    x *= b+1;
    x--;
    ll c = x - z + 1;
    y = power(k) ;
    //cout <<(y+a-1)/a-(c+a-1)/a<<" ";
    return (y+a-1)/a-(c+a-1)/a;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,k,i,ans  = 1;
    cin>>n>>k;
    ll a[n/k],b[n/k];
    for(i=0;i<n/k;i++)
        cin>>a[i];
    for(i=0;i<n/k;i++)
        cin>>b[i];

    for(i=0;i<n/k;i++)
        ans = (ans * func(k,a[i],b[i]))%N;
    cout<<ans;
    return 0;
}


//Pasha And Phone
#include <bits/stdc++.h>

#define ll long long
#define Module 1000000007

using namespace std;

ll n, k, answer;
vector<int> a, b;

ll Quantify( int length, int divisor ){
	ll k = 0;
	for ( int i = 0; i < length; i++ ){
		k = k*10 + 9;
	}
	return ( k / divisor + 1 );
}

ll Count( ll divisor, ll exception, ll length ){
	ll answer = 0;
	for ( int i = 0; i < length; i++ ){
		answer = answer * 10 + 9;
	}
	ll minus = exception;
	for ( int i = 1; i < length; i++ ){
		minus = minus * 10 + 9;
	}
	ll plus = 0;
	if ( exception > 0 ){
		plus = exception - 1;
		for ( int i = 1; i < length; i++ ){
			plus = plus * 10 + 9;
		}
	}
	return ( answer / divisor - minus / divisor + plus / divisor + ( exception > 0 ) );
}

int main(){
	scanf( "%lld %lld", &n, &k );
	a.resize( n/k );
	b.resize( n/k );
	for ( int i = 0; i < n/k; i++ ){
		scanf( "%lld", &a[i] );
	}
	for ( int i = 0; i < n/k; i++ ){
		scanf( "%lld", &b[i] );
	}
	answer = 1;
	for ( int i = 0; i < n/k; i++ ){
		//printf( "%lld\n", Count( a[i], b[i], k ) );
		answer *= Count( a[i], b[i], k );
		answer %= Module;
	}
	printf( "%lld\n", answer );
	return 0;
}


//Pasha And Phone
#include <bits/stdc++.h>

#define ll long long
#define Module 1000000007

using namespace std;

ll n, k, answer;
vector<int> a, b;

ll Quantify( int length, int divisor ){
	ll k = 0;
	for ( int i = 0; i < length; i++ ){
		k = k*10 + 9;
	}
	return ( k / divisor + 1 );
}

ll Count( ll divisor, ll exception, ll length ){
	ll r = exception;
	for ( int i = 1; i < length; i++ ){
		r = r*10+9;
	}
	ll l;
	if ( !exception ){
		l = -1;
	} else {
		l = exception - 1;
	}
	if ( l > 0 ){
		for ( int i = 1; i < length; i++ ){
			l = l*10 + 9;
		}
	}
	ll excess = ( r / divisor ) - ( l / divisor );
	ll all = Quantify( length, divisor );
	return ( all - excess - ( exception == 0 ) );
}

int main(){
	scanf( "%lld %lld", &n, &k );
	a.resize( n/k );
	b.resize( n/k );
	for ( int i = 0; i < n/k; i++ ){
		scanf( "%lld", &a[i] );
	}
	for ( int i = 0; i < n/k; i++ ){
		scanf( "%lld", &b[i] );
	}
	answer = 1;
	for ( int i = 0; i < n/k; i++ ){
		//printf( "%lld\n", Count( a[i], b[i], k ) );
		answer *= Count( a[i], b[i], k );
		answer %= Module;
	}
	printf( "%lld\n", answer );
	return 0;
}


//Pasha And Phone
#include <bits/stdc++.h>

#define ll long long
#define Module 1000000007

using namespace std;

ll n, k, answer;
vector<int> a, b;

ll Quantify( int length, int divisor ){
	ll k = 0;
	for ( int i = 0; i < length; i++ ){
		k = k*10 + 9;
	}
	return ( k / divisor + 1 );
}

ll Count( ll divisor, ll exception, ll length ){
	ll r = exception;
	for ( int i = 1; i < length; i++ ){
		r = r*10+9;
	}
	ll l;
	if ( !exception ){
		l = 0;
	} else {
		l = exception - 1;
	}
	for ( int i = 1; i < length; i++ ){
		l = l*10 + 9;
	}
	ll excess = ( r / divisor ) - ( l / divisor );
	ll all = Quantify( length, divisor );
	return ( all - excess - ( exception == 0 ) );
}

int main(){
	scanf( "%lld %lld", &n, &k );
	a.resize( n/k );
	b.resize( n/k );
	for ( int i = 0; i < n/k; i++ ){
		scanf( "%lld", &a[i] );
	}
	for ( int i = 0; i < n/k; i++ ){
		scanf( "%lld", &b[i] );
	}
	answer = 1;
	for ( int i = 0; i < n/k; i++ ){
		answer *= Count( a[i], b[i], k );
		answer %= Module;
	}
	printf( "%lld\n", answer );
	return 0;
}


//Pasha And Phone
#include <bits/stdc++.h>

#define ll long long
#define Module 1000000007

using namespace std;

ll n, k, answer;
vector<int> a, b;

ll Quantify( int length, int divisor ){
	ll k = 0;
	for ( int i = 0; i < length; i++ ){
		k = k*10 + 9;
	}
	return ( k / divisor + 1 );
}

ll Count( ll divisor, ll exception, ll length ){
	ll r = exception;
	for ( int i = 1; i < length; i++ ){
		r = r*10+9;
	}
	ll l;
	if ( !exception ){
		l = 0;
	} else {
		l = exception - 1;
	}
	for ( int i = 1; i < length; i++ ){
		l = l*10 + 9;
	}
	ll excess = ( r / divisor ) - ( l / divisor );
	ll all = Quantify( length, divisor );
	return ( all - excess );
}

int main(){
	scanf( "%lld %lld", &n, &k );
	a.resize( n/k );
	b.resize( n/k );
	for ( int i = 0; i < n/k; i++ ){
		scanf( "%lld", &a[i] );
	}
	for ( int i = 0; i < n/k; i++ ){
		scanf( "%lld", &b[i] );
	}
	answer = 1;
	for ( int i = 0; i < n/k; i++ ){
		answer *= Count( a[i], b[i], k );
		answer %= Module;
	}
	printf( "%lld\n", answer );
	return 0;
}


//Pasha And Phone
#include <bits/stdc++.h>

#define ll long long
#define Module 1000000007

using namespace std;

ll n, k, answer;
vector<int> a, b;

ll Quantify( int length, int divisor ){
	ll k = 0;
	for ( int i = 0; i < length; i++ ){
		k = k*10 + 9;
	}
	return ( k / divisor + 1 );
}

ll Count( ll divisor, ll exception, ll length ){
	ll r = exception;
	for ( int i = 1; i < length; i++ ){
		r = r*10+9;
	}
	ll l;
	if ( !exception ){
		l = 0;
	} else {
		l = exception - 1;
	}
	if ( l > 0 ){
		for ( int i = 1; i < length; i++ ){
			l = l*10 + 9;
		}
	}
	ll excess = ( r / divisor ) - ( l / divisor );
	ll all = Quantify( length, divisor );
	return ( all - excess - ( exception == 0 ) );
}

int main(){
	scanf( "%lld %lld", &n, &k );
	a.resize( n/k );
	b.resize( n/k );
	for ( int i = 0; i < n/k; i++ ){
		scanf( "%lld", &a[i] );
	}
	for ( int i = 0; i < n/k; i++ ){
		scanf( "%lld", &b[i] );
	}
	answer = 1;
	for ( int i = 0; i < n/k; i++ ){
		//printf( "%lld\n", Count( a[i], b[i], k ) );
		answer *= Count( a[i], b[i], k );
		answer %= Module;
	}
	printf( "%lld\n", answer );
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long

int main(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
    #endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout<<fixed;
    srand(time(0));

    const int mod = 1e9 + 7;

    int n,k;cin>>n>>k;
    int nk = n / k;
    ll ans = 1;
    vector<ll> a(nk), b(nk);
    for(int i=0;i<nk;i++){
    	cin>>a[i];
    }
    for(int i=0;i<nk;i++){
    	cin>>b[i];
    }
    for(int i=0;i<nk;i++){
    	ll d = ceil((pow(10, k)) * 1.0 / a[i]);
    	ll x = ceil((b[i] * pow(10, k - 1)) * 1.0 / a[i]);
    	ll y = ceil(((b[i] + 1) * pow(10, k - 1)) * 1.0 / a[i]);
    	d -= (y - x);
    	(ans *= d) %= mod;
    }
    cout<<ans;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long

int main(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
    #endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout<<fixed;
    srand(time(0));

    const int mod = 1e9 + 7;

    int n,k;cin>>n>>k;
    int nk = n / k;
    ll ans = 1;
    vector<ll> a(nk), b(nk);
    for(int i=0;i<nk;i++){
    	cin>>a[i];
    }
    for(int i=0;i<nk;i++){
    	cin>>b[i];
    }
    for(int i=0;i<nk;i++){
    	ll d = (pow(10, k) - 1) / a[i] + (b[i] != 0);
    	ll x = (b[i] * pow(10, k - 1) - 1) / a[i];
    	ll y = ((b[i] + 1) * pow(10, k - 1) - 1) / a[i];
    	d -= (y - x);
    	(ans *= d) %= mod;
    }
    cout<<ans;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long

int main(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
    #endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout<<fixed;
    srand(time(0));

    const int mod = 1e9 + 7;

    int n,k;cin>>n>>k;
    int nk = n / k;
    ll ans = 1;
    vector<ll> a(nk), b(nk);
    for(int i=0;i<nk;i++){
    	cin>>a[i];
    }
    for(int i=0;i<nk;i++){
    	cin>>b[i];
    }
    for(int i=0;i<nk;i++){
    	ll d = (pow(10, k) - 1) / a[i] + 1;
    	ll x = (b[i] * pow(10, k - 1) - 1) / a[i];
    	ll y = ((b[i] + 1) * pow(10, k - 1) - 1) / a[i];
    	d -= (y - x);
    	(ans *= d) %= mod;
    }
    cout<<ans;

    return 0;
}


#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;

const int N = 1e5 + 5;
const ll mod = 1e9 + 7;
const ll inf = 1e9;

int  main(){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cerr.tie(nullptr);

	int n;
	cin >> n;
	ll a[n + 1];
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	sort(a + 1, a + n + 1);
	ll ans = a[n/2 + 1] - a[1];
	for (int i = 1; i <= n/2; i++)
		ans = min (ans, a[i + n/2] - a[i]);
	cout << ans;
}


#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;

const int N = 1e5 + 5;
const ll mod = 1e9 + 7;
const ll inf = 1e9;

ll cal(ll l, ll r, ll d){
	return r / d - (l / d + (l % d != 0)) + 1;
}

int  main(){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cerr.tie(nullptr);

	int n, k;
	cin >> n >> k;
	ll a[n + 1], b[n + 1];
	for (int i = 1; i <= n / k; i++) cin >> a[i];
	for (int i = 1; i <= n / k; i++) cin >> b[i];

	ll ans = 1;

	for (ll d = 1; d <= n / k; d++){
		ll l = 0, r = 0;
		for (ll t = 1; t <= k; t++){
			r = r * 10 + 9;
		}
		ll u = b[d], v = b[d];
		for (ll t = 1; t < k; t++){
			u = u * 10;
			v = v * 10 + 9;
		}
		ans = ans * (cal(l, r, a[d]) - cal(u, v, a[d])) % mod;
	}

	cout << ans;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	ll n,k,g;
	cin>>n>>k;
	g = n/k;
	ll a[g],b[g];
	for (int i=0;i<g;i++) cin>>a[i];
	for (int i=0;i<g;i++) cin>>b[i];
    ll ans=1,tk=1;
    for (int i=0;i<k;i++) tk*=10;
    ll mod = 1e9+7;
    for (int i=0;i<g;i++){
		ll cans = (tk-1)/a[i]+1;
		cans -= ((b[i]+1)*tk/10-1)/a[i]+1;
		cans += (b[i]*tk/10-1)/a[i]+1;
		ans = (ans*cans)%mod;
    }
    cout<<ans<<'\n';
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	ll n,k,g;
	cin>>n>>k;
	g = n/k;
	ll a[g],b[g];
	for (int i=0;i<g;i++) cin>>a[i];
	for (int i=0;i<g;i++) cin>>b[i];
    ll ans=1,tk=1;
    for (int i=0;i<k;i++) tk*=10;
    ll mod = 1e9+7;
    for (int i=0;i<g;i++){
		ll cans = (tk-1)/a[i];
		cans -= ((b[i]+1)*tk/10-1)/a[i];
		cans += (b[i]*tk/10-1)/a[i];
		if (b[i] != 0) cans++;
		ans = (ans*cans)%mod;
    }
    cout<<ans<<'\n';
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	ll n,k,g;
	cin>>n>>k;
	g = n/k;
	ll a[g],b[g];
	ll mod = 1e9+7;
	for (int i=0;i<g;i++) cin>>a[i];
	for (int i=0;i<g;i++) cin>>b[i];
    ll ans=1,tk=1;
    for (int i=0;i<k;i++) tk*=10;
    for (int i=0;i<g;i++){
		ll cans = (tk-1)/a[i]+1;
		cans -= ((b[i]+1)*tk/10-1)/a[i]+1;
		if (b[i] > 0)cans += (b[i]*tk/10-1)/a[i];
		if (b[i]) cans++;
		ans = (ans*cans)%mod;
    }
    cout<<ans<<'\n';
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	ll n,k,g;
	cin>>n>>k;
	g = n/k;
	ll a[g],b[g];
	ll mod = 1e9+7;
	for (int i=0;i<g;i++) cin>>a[i];
	for (int i=0;i<g;i++) cin>>b[i];
	if (k == 1){
        ll ans = 1;
        for (int i=0;i<g;i++){
            ll cans = 9/a[i] + 1;
            if (b[i]==0 || a[i]%b[i]==0) cans--;
            ans = (ans*cans)%mod;
        }
        cout<<ans<<'\n';
        return 0;
	}
    ll ans=1,tk=1;
    for (int i=0;i<k;i++) tk*=10;
    for (int i=0;i<g;i++){
		ll cans = (tk-1)/a[i];
		cans -= ((b[i]+1)*tk/10-1)/a[i];
		cans += (b[i]*tk/10-1)/a[i];
		if (b[i]) cans++;
		ans = (ans*cans)%mod;
    }
    cout<<ans<<'\n';
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	ll n,k,g;
	cin>>n>>k;
	g = n/k;
	ll a[g],b[g];
	ll mod = 1e9+7;
	for (int i=0;i<g;i++) cin>>a[i];
	for (int i=0;i<g;i++) cin>>b[i];
	if (k == 1){
        ll ans = 1;
        for (int i=0;i<g;i++){
            ll cans = 9/a[i] + 1;
            if (b[i]==0 || b[i]%a[i]==0) cans--;
            ans = (ans*cans)%mod;
        }
        cout<<ans<<'\n';
        return 0;
	}
    ll ans=1,tk=1;
    for (int i=0;i<k;i++) tk*=10;
    for (int i=0;i<g;i++){
		ll cans = (tk-1)/a[i];
		cans -= ((b[i]+1)*tk/10-1)/a[i];
		cans += (b[i]*tk/10-1)/a[i];
		if (b[i]) cans++;
		ans = (ans*cans)%mod;
    }
    cout<<ans<<'\n';
	return 0;
}


#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
#pragma GCC optimize("Ofast")

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
#define int long long int
typedef complex<long double> cd;
const long double pi=acos(-1);
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <db, db> pdd;
typedef vector<int> vi;
typedef vector<vector<int> > matrix;

#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define reset(x,v) memset(x,v,sizeof(x))

#define fi first
#define se second
#define endl "\n"
#define debug(x) (cerr << #x << ": " << x << "\n")
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
#define all(x) x.begin(),x.end()
#define pii pair<int,int>

inline ll gcd(ll a,ll b){if(a==0) return b;return gcd(b%a,a);}
inline ll power(ll a,ll n,ll m){if(n==0)return 1;ll p=power(a,n/2,m);p=(p%m*p%m)%m;if(n%2) return (p%m*a%m)%m;else return p;}
const double EPS = 1e-9;
const ll MOD =998244353;
const ll hell=1000000007;
const int INF = 1e18;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
template<typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
std::mt19937 rng(seed);

double startTime;
double getCurrentTime() {
    return ((double)clock() - startTime) / CLOCKS_PER_SEC;
}
const int dx[] = { -1, 0, 1, 0 };
const int dy[] = { 0, 1, 0, -1 };

const int N=200005;

void solve()
{

    int n,k;
    cin>>n>>k;
    int z=n/k;
    int a[z+1],b[z+1];
    for(int i=1;i<=z;i++)
        cin>>a[i];
    for(int j=1;j<=z;j++)
        cin>>b[j];
    int pr[k+1];
    pr[0]=1;
    for(int i=1;i<=k;i++)
        pr[i]=pr[i-1]*10;
    int ans=1;int cnt;
    for(int i=1;i<=z;i++)
    {

        int x=pr[k]-1;
        x=x/a[i];
        cnt=x+1;
        int md=(b[i]*pr[k-1])%a[i];
        md=(a[i]-md)%a[i];
        if(md<=(pr[k-1]-1))
        {
            x=pr[k-1]-1-md;
            x=x/a[i];
            cnt-=(x+1);
        }
        ans=(ans*(cnt))%hell;
    }
    cout<<ans<<endl;

}

int32_t main()
{
    IOS;

    int t;
    t=1;
   // cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}


#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
#pragma GCC optimize("Ofast")

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
#define int long long int
typedef complex<long double> cd;
const long double pi=acos(-1);
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <db, db> pdd;
typedef vector<int> vi;
typedef vector<vector<int> > matrix;

#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define reset(x,v) memset(x,v,sizeof(x))

#define fi first
#define se second
#define endl "\n"
#define debug(x) (cerr << #x << ": " << x << "\n")
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
#define all(x) x.begin(),x.end()
#define pii pair<int,int>

inline ll gcd(ll a,ll b){if(a==0) return b;return gcd(b%a,a);}
inline ll power(ll a,ll n,ll m){if(n==0)return 1;ll p=power(a,n/2,m);p=(p%m*p%m)%m;if(n%2) return (p%m*a%m)%m;else return p;}
const double EPS = 1e-9;
const ll MOD =998244353;
const ll hell=1000000007;
const int INF = 1e18;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
template<typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
std::mt19937 rng(seed);

double startTime;
double getCurrentTime() {
    return ((double)clock() - startTime) / CLOCKS_PER_SEC;
}
const int dx[] = { -1, 0, 1, 0 };
const int dy[] = { 0, 1, 0, -1 };

const int N=200005;

void solve()
{

    int n,k;
    cin>>n>>k;
    int z=n/k;
    int a[z+1],b[z+1];
    for(int i=1;i<=z;i++)
        cin>>a[i];
    for(int j=1;j<=z;j++)
        cin>>b[j];
    int pr[k+1];
    pr[0]=1;
    for(int i=1;i<=k;i++)
        pr[i]=pr[i-1]*10;
    int ans=1;int cnt;
    for(int i=1;i<=z;i++)
    {

        int x=pr[k]-1;
        x=x/a[i];
        cnt=x+1;
        int md=(b[i]*pr[k-1])%a[i];
        md=(a[i]-md)%a[i];
        if(md<=(pr[k-1]-1))
        {
            x=pr[k-1]-1-md;
            x=x/a[i];
            cnt-=(x+1);
        }
        ans=(ans*(cnt));
    }
    cout<<ans<<endl;

}

int32_t main()
{
    IOS;

    int t;
    t=1;
   // cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ld double
#define lld long double
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define mod 1000000007
#define clean(a,k) memset(a, k, sizeof(a))
#define runner(i,k,m) for(i=k;i<=m;i++)
#define cases(T) cin>>T;while(T--)
#define maxx 9223372036854775807
using namespace std;
//cout<<setprecision(18)<<fixed<<ans<<endl;	freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
int main() {
	int m,n,i,p,x;
	long long int ans=1,k2=1,k1=1,a[100005],b[100005];
	cin>>m>>n;
	k1=k1*pow(10,n);
	k2=k1/10;
	k1--;
	for(i=1; i<=m/n; i++)
		cin>>a[i];
	for(i=1; i<=m/n; i++)
		cin>>b[i];
	for(i=1; i<=m/n; i++) {
		p=k1/a[i]+1;
		if(b[i]!=0)p=p-((k2*(b[i]+1)-1)/a[i]-(k2*b[i]-1)/a[i]);
		else if(b[i]==0)p=p-(k2-1)/a[i]-1;
		ans=ans*p%1000000007;
	}
	cout<<ans%1000000007<<endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> p2;
#define sz(a) ll(a.size()
ll a[100005],hell=pow(10,9)+7;
void solve(){
	ll n,k,res=1;
	cin>>n>>k;
	ll m=n/k,tr=pow(10,k)-1;
	for(ll i=1;i<=m;i++)
	cin>>a[i];
	for(ll i=1;i<=m;i++){
		ll x;
		cin>>x;
		ll val=tr/a[i]+1;
		ll q=pow(10,k-1)*x,r=pow(10,k-1)-1;;
		q%=a[i];
		if(q){
			q=a[i]-q;
			val-=(r/a[i])+1;
			if((r%a[i])<q)
			val++;
		}
		else
		val-=r/a[i]+1;
		res=(res*val)%hell;
	}
	cout<<res;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll qc=1;
    //cin>>qc;
    for(ll i=1;i<=qc;i++)
    solve();
}


#include <iostream>
#include <ctime>
#include <iomanip>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
#include <cmath>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <chrono>
#include <stack>
#include <cassert>
#include <queue>
#include <deque>
#include <climits>
#include <cstring>
#include <random>
#include <bitset>

using namespace std;

typedef long long ll;

const int mod = 1e9 + 7;

int mul(int a, int b) {
    ll res = (ll)a * b;
    return res % mod;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

#ifdef LOCAL
assert(freopen("input.txt", "r", stdin));
assert(freopen("output.txt", "w", stdout));
#endif

    int n, k;
    cin >> n >> k;
    vector<int> a(n / k);
    vector<int> b(n / k);
    for (auto &t : a) {
        cin >> t;
    }
    for (auto &t : b) {
        cin >> t;
    }
    int ans = 1;

    for (int i = 0; i < n / k; i++) {
        int ul = (b[i] + 1) * pow(10, k - 1);//r)
        int dl = b[i] * pow(10, k - 1);
        int all = pow(10, k) / a[i] + 1;
        int u = ul / a[i];
        int d = (dl + a[i] - 1) / a[i];
        int ins = u - d + 1;
        int cur = all - ins;
        ans = mul(ans, cur);
    }
    cout << ans << '\n';
}


#include <iostream>
#include <ctime>
#include <iomanip>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
#include <cmath>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <chrono>
#include <stack>
#include <cassert>
#include <queue>
#include <deque>
#include <climits>
#include <cstring>
#include <random>
#include <bitset>

using namespace std;

typedef long long ll;

const int mod = 1e9 + 7;

int mul(int a, int b) {
    ll res = (ll)a * b;
    return res % mod;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

#ifdef LOCAL
assert(freopen("input.txt", "r", stdin));
assert(freopen("output.txt", "w", stdout));
#endif

    int n, k;
    cin >> n >> k;
    vector<int> a(n / k);
    vector<int> b(n / k);
    for (auto &t : a) {
        cin >> t;
    }
    for (auto &t : b) {
        cin >> t;
    }
    int ans = 1;

    for (int i = 0; i < n / k; i++) {
        int ul = (b[i] + 1) * pow(10, k - 1) - 1;//r]
        int dl = b[i] * pow(10, k - 1);
        int u = (ul) / a[i];
        int d = (dl + a[i] - 1) / a[i];
        int ins = u - d + 1;
        int all = (pow(10, k) - 1) / a[i] + 1;

        int cur = all - ins;
//        cerr << "div " << a[i] << " start " << b[i] << " " << cur << endl;
        ans = mul(ans, cur);
    }
    cout << ans << '\n';
}


#include <iostream>
#include <ctime>
#include <iomanip>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
#include <cmath>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <chrono>
#include <stack>
#include <cassert>
#include <queue>
#include <deque>
#include <climits>
#include <cstring>
#include <random>
#include <bitset>

using namespace std;

typedef long long ll;

const int mod = 1e9 + 7;

int mul(int a, int b) {
    ll res = (ll)a * b;
    return res % mod;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

#ifdef LOCAL
assert(freopen("input.txt", "r", stdin));
assert(freopen("output.txt", "w", stdout));
#endif

    int n, k;
    cin >> n >> k;
    vector<int> a(n / k);
    vector<int> b(n / k);
    for (auto &t : a) {
        cin >> t;
    }
    for (auto &t : b) {
        cin >> t;
    }
    int ans = 1;

    for (int i = 0; i < n / k; i++) {
        int ul = (b[i] + 1) * pow(10, k - 1) - 1;//r]
        int dl = b[i] * pow(10, k - 1);
        int u = (ul) / a[i];
        int d = (dl + a[i] - 1) / a[i];
        int ins = u - d + 1;
        int all = (pow(10, k) - 1) / a[i] + 1;

        int cur = all - ins;
        cerr << "div " << a[i] << " start " << b[i] << " " << cur << endl;
        ans = mul(ans, cur);
    }
    cout << ans << '\n';
}


#include <bits/stdc++.h>
using namespace std;
#define fast                                                                   \
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define f(i, n) for (i = 0; i < n; i++)
#define fo(i,a,n) for ( i = a; i <= n; i++)
#define F first
#define S second
#define pii pair<int,int>
#define all(v) v.begin(),v.end()
#define pb push_back
#define pf pop_front
#define PB pop_back
#define pll pair<long long, long long>
#define vi vector<int>
#define vl vector<long>
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define max4(a,b,c,d) max(a,max(b,max(c,d)))
#define min4(a,b,c,d) min(a,min(b,min(c,d)))
#define mp make_pair
#define x0 p
#define y0 q
//#define mod (1e9+7)
const int N = 1e5+10;

ll power(ll base, ll exp)
{
    if(exp == 0)
     return 1;

    ll p=power(base, exp/2);
    p=(p*p);
    return (exp%2 == 0)?p:(base * p);
}

void solve() {
    ll n, m, i, p = 1, q, k, r = 0, mod = 1000000007;
    ll power[20];
    power[0] = 1;
    for(i=1; i<=9; i++){
        power[i] = 10 * power[i-1];
    }
    cin >> n >> k;
    q = n / k;
    ll a[q+10], b[q+10];
    f(i,q) {
        cin >> a[i];
    }
    f(i,q) {
        cin >> b[i];
    }
    f(i,q) {
        r = 1 + (power[k]-1)/a[i];
        if(b[i]){
            r -= ((b[i] + 1) * power[k-1] - 1) / a[i];
            r += (b[i] * power[k-1] - 1) / a[i];
        }
        else{
            r -= 1 + (1 * power[k-1] - 1) / a[i];
        }
        r %= mod;
        p = (p*r)%mod;
    }
    cout<<p;
}

int main() {
    fast
    ll t;
    //cin>>t;
    t=1;while(t--){solve();}
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define int long long

#define MOD 1000000007
#define maxlen 9223372036854775807
#define minlen -9223372036854775807

int gcd(int a,int b){if(b==0)return a;return gcd(b,a%b);}
vector<int> primeFact(int n){vector<int> ans;for(int t=2;t<=sqrt(n);t++){if(n%t==0){ans.push_back(t);while(n%t==0){n=n/t;}}}if(n>2)ans.push_back(n);return ans;}
vector<int> fact(int n){vector<int> ans;for(int i=1;i<=sqrt(n);i++){if(n%i==0){if( i*i == n ){ans.push_back(i);}else{ans.push_back(i);ans.push_back(n/i);}}}return ans;}
int powerr(int base,int exp,int mod) { if(exp==0)return 1;int t = powerr(base,exp/2,mod)%mod;if(exp%2==0){return (t%mod*t%mod)%mod;}else{return (t%mod*t%mod*base%mod)%mod;}}
void fastio(){ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);}

int dig( int n ){
	int ans = 0;
	for(int i=0;i<n;i++){
		ans = ans*10+9;
	}
	return ans;
}

int solve( int n, int k ){
	int ans = n;
	for(int i=1;i<k;i++){
		ans = ans*10;
	}
	return ans;
}

int32_t main(){
	fastio();

	int n,k;
	cin >> n >> k;

	vector<int> a(n/k),b(n/k);
	for(int i=0;i<n/k;i++){
		cin >> a[i];
	}
	for(int i=0;i<n/k;i++){
		cin >> b[i];
	}

	int ans = 1,nu = dig(k),nm=dig(k-1);
	int lans=0,error;
	for(int i=0;i<n/k;i++){
		lans = 0;
		error = solve( b[i] , k );
		int t = a[i] - error%a[i];

		lans = ( nu/a[i] +1) - ( (error%a[i]==0?1:0) + (nm)/a[i] + ( t<=(nm)%a[i]?1:0 ) );
		//cout << error << " " << ( (nm+1)/a[i] + ( t<=(nm+1)%a[i]?1:0 ) ) << " " << lans << "\n";
		ans = (( (ans%MOD) * (lans%MOD) )%MOD);
	}

	cout << ans << "\n";

	return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main(){
int n,k;
cin>>n>>k;
int a[n/k],b[n/k];
for(int i=0;i<n/k;i++){
cin>>a[i];
}
for(int i=0;i<n/k;i++){
cin>>b[i];
}
int val[n/k];
long long ans=1;
for(int i=0;i<n/k;i++){
val[i]=((int)pow(10,k)-1)/a[i];
int max=((int)pow(10,k-1)*(b[i]+1)-1);
int min=((int)pow(10,k-1)*(b[i])-1);
min=min>0?min:0;
int xx=max/a[i]-min/a[i];
val[i]-=xx;
if(b[i]!=0){
val[i]++;
}
ans*=val[i];
ans%=1000000007;
}

cout<<ans<<endl;

return 0;

}


#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <cmath>
#include <set>
#include <map>
#include <cstdio>
#include <stdlib.h>
#include <stack>
#include <numeric>
#include <bitset>
#include <cctype>
#include <list>
#include <assert.h>
#include <random>
#include <unordered_map>
#include <ctime>
typedef long long ll;
#define MAX 100005
using namespace std;
#define INF 2147483647
#define infL (1LL<<60)
#define inf (1<<30)
#define MOD 1000000007
#define EPS 1e-9
#define Gr 9.8
#define PI acos(-1)
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define REQ(i,n) for(int (i)=1;(i)<=(int)(n);(i)++)
#define lch (rt<<1)
#define rch (rt<<1|1)
typedef pair<int, int> pii;
typedef long double ld;
typedef unsigned int uint;
bool debug = 0;
int n,m,k;
int dx[4] = {0,1,0,-1}, dy[4] = {1,0,-1,0};
ll ln, lk, lm;

int cal(int x, int div) {
    if (x<0) return 0;
    return x/div+1;
}
int a[MAX],b[MAX];
void fmain() {
    scanf("%d%d", &n, &k); m=n/k;
    REP(i,m) scanf("%d", a+i);
    REP(i,m) scanf("%d", b+i);
    int k10=1;
    REQ(i,k) k10*=10;
    ll ans = 1;
    REP(i,m) {
        int tt = cal(k10-1, a[i]);
        int tar = k10/10 * b[i];
        tt -= cal(k10/10*(b[i]+1)-1, a[i]) - cal(tar-1, a[i]);
        ans *= tt; ans %= MOD;
    }
    printf("%lld\n",ans);
}
int main() {
    fmain();
    return 0;
}


#pragma GCC optimize(2)
#include <bits/stdc++.h>
#include <cstdio>
#include <algorithm>
#include <cstring>
#define pb push_back
#define pii pair<int,int>
#define mpp make_pair
#define fi first
#define se second
#define re register
#define clr(a,b) memset(a,b,sizeof(a))

// //debug
// #define FIN freopen("in.txt","r",stdin);
#define debug1(x) cout << "[" << #x << " = " << (x) << "]\n"
#define debug2(x,y) cout << "[" << #x << " = " << (x) << "  " << #y << " = " << (y) << "]\n"
#define debug3(x,y,z) cout << "[" << #x << " = " << (x) << "  " << #y << " = " << (y) << "  " << #z << " = " << (z) << "]\n"

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll LINF = 2e18 + 7;
const int INF = 1e9 + 7;
const int mod = 1e9 + 7;
const double eps = 1e-6;

const int maxn = 1e5 + 7;
const int maxm = 2e5 + 7;

ll a[maxn], b[maxn];
ll p[12];

int main() {
	p[0] = 1;
	for(int i = 1;i <= 9;++i) p[i] = p[i-1] * 10;
	int n,k;scanf("%lld%lld",&n,&k);
	for(int i = 1; i <= n / k;++i) scanf("%lld",&a[i]);
	for(int i = 1; i <= n / k;++i) scanf("%lld",&b[i]);
	ll res = 0;
	for(int i = 1;i <= n / k;++i){
		ll de;
		if(k == 1){
			if(b[i] % a[i] == 0) de = 1;
			else de = 0;
		}
		else de = ((b[i] + 1) * p[k-1] - 1) / a[i] - max(1ll*0,b[i]*p[k-1]-1) / a[i] + (b[i] == 0);
		// if(((b[i] + 1) * p[k-1] - 1) == max(1ll*0,b[i]*p[k-1]-1)) de = 1;
		if(i == 1) res += ((p[k] - 1) / a[i] + 1 - de) % mod;
		else res = (((res * ((p[k] - 1) / a[i] + 1 - de)) % mod) + mod) % mod;
	}
	printf("%lld\n", res);
    return 0;
}

/*

1 1
4
0

*/


#pragma GCC optimize(2)
#include <bits/stdc++.h>
#include <cstdio>
#include <algorithm>
#include <cstring>
#define pb push_back
#define pii pair<int,int>
#define mpp make_pair
#define fi first
#define se second
#define re register
#define clr(a,b) memset(a,b,sizeof(a))

// //debug
// #define FIN freopen("in.txt","r",stdin);
#define debug1(x) cout << "[" << #x << " = " << (x) << "]\n"
#define debug2(x,y) cout << "[" << #x << " = " << (x) << "  " << #y << " = " << (y) << "]\n"
#define debug3(x,y,z) cout << "[" << #x << " = " << (x) << "  " << #y << " = " << (y) << "  " << #z << " = " << (z) << "]\n"

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll LINF = 2e18 + 7;
const int INF = 1e9 + 7;
const int mod = 1e9 + 7;
const double eps = 1e-6;

const int maxn = 1e5 + 7;
const int maxm = 2e5 + 7;

ll a[maxn], b[maxn];
ll p[12];

int main() {
	p[0] = 1;
	for(int i = 1;i <= 9;++i) p[i] = p[i-1] * 10;
	int n,k;scanf("%lld%lld",&n,&k);
	for(int i = 1; i <= n / k;++i) scanf("%lld",&a[i]);
	for(int i = 1; i <= n / k;++i) scanf("%lld",&b[i]);
	ll res = 0;
	for(int i = 1;i <= n / k;++i){
		ll de;
		if(k == 1){
			if(b[i] % a[i] == 0) de = 1;
			else de = 0;
		}
		else de = ((b[i] + 1) * p[k-1] - 1) / a[i] - max(1ll*0,b[i]*p[k-1]-1) / a[i];
		if(b[i] == 0) de++;
		// if(((b[i] + 1) * p[k-1] - 1) == max(1ll*0,b[i]*p[k-1]-1)) de = 1;
		if(i == 1) res += ((p[k] - 1) / a[i] + 1 - de) % mod;
		else res = (((res * ((p[k] - 1) / a[i] + 1 - de)) % mod) + mod) % mod;
	}
	printf("%lld\n", res);
    return 0;
}

/*

1 1
4
0

*/


#pragma GCC optimize(2)
#include <bits/stdc++.h>
#include <cstdio>
#include <algorithm>
#include <cstring>
#define pb push_back
#define pii pair<int,int>
#define mpp make_pair
#define fi first
#define se second
#define re register
#define clr(a,b) memset(a,b,sizeof(a))

// //debug
// #define FIN freopen("in.txt","r",stdin);
#define debug1(x) cout << "[" << #x << " = " << (x) << "]\n"
#define debug2(x,y) cout << "[" << #x << " = " << (x) << "  " << #y << " = " << (y) << "]\n"
#define debug3(x,y,z) cout << "[" << #x << " = " << (x) << "  " << #y << " = " << (y) << "  " << #z << " = " << (z) << "]\n"

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll LINF = 2e18 + 7;
const int INF = 1e9 + 7;
const int mod = 1e9 + 7;
const double eps = 1e-6;

const int maxn = 1e5 + 7;
const int maxm = 2e5 + 7;

ll a[maxn], b[maxn];
ll p[12];

int main() {
	p[0] = 1;
	for(int i = 1;i <= 9;++i) p[i] = p[i-1] * 10;
	int n,k;scanf("%lld%lld",&n,&k);
	for(int i = 1; i <= n / k;++i) scanf("%lld",&a[i]);
	for(int i = 1; i <= n / k;++i) scanf("%lld",&b[i]);
	ll res = 1;
	for(int i = 1;i <= n / k;++i){
		ll de = ((b[i] + 1) * p[k-1] - 1) / a[i] - (b[i] * p[k-1]-1) / a[i];
		res = (((res * ((p[k] - 1) / a[i] + (b[i] != 0) - de)) % mod) + mod) % mod;
	}
	printf("%lld\n", res);
    return 0;
}


#pragma GCC optimize(2)
#include <bits/stdc++.h>
#include <cstdio>
#include <algorithm>
#include <cstring>
#define pb push_back
#define pii pair<int,int>
#define mpp make_pair
#define fi first
#define se second
#define re register
#define clr(a,b) memset(a,b,sizeof(a))

// //debug
// #define FIN freopen("in.txt","r",stdin);
#define debug1(x) cout << "[" << #x << " = " << (x) << "]\n"
#define debug2(x,y) cout << "[" << #x << " = " << (x) << "  " << #y << " = " << (y) << "]\n"
#define debug3(x,y,z) cout << "[" << #x << " = " << (x) << "  " << #y << " = " << (y) << "  " << #z << " = " << (z) << "]\n"

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll LINF = 2e18 + 7;
const int INF = 1e9 + 7;
const int mod = 1e9 + 7;
const double eps = 1e-6;

const int maxn = 1e5 + 7;
const int maxm = 2e5 + 7;

ll a[maxn], b[maxn];
ll p[12];

int main() {
	p[0] = 1;
	for(int i = 1;i <= 9;++i) p[i] = p[i-1] * 10;
	int n,k;scanf("%lld%lld",&n,&k);
	for(int i = 1; i <= n / k;++i) scanf("%lld",&a[i]);
	for(int i = 1; i <= n / k;++i) scanf("%lld",&b[i]);
	ll res = 0;
	for(int i = 1;i <= n / k;++i){
		ll de;
		if(k == 1){
			if(b[i] % a[i] == 0) de = 1;
			else de = 0;
		}
		else de = ((b[i] + 1) * p[k-1] - 1) / a[i] - max(1ll*0,b[i]*p[k-1]-1) / a[i];
		// if(((b[i] + 1) * p[k-1] - 1) == max(1ll*0,b[i]*p[k-1]-1)) de = 1;
		if(i == 1) res += ((p[k] - 1) / a[i] + 1 - de) % mod;
		else res = (((res * ((p[k] - 1) / a[i] + 1 - de)) % mod) + mod) % mod;
	}
	printf("%lld\n", res);
    return 0;
}

/*

1 1
4
0

*/


#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int MOD = (int)(1e9 + 7);
const int MAXN = (int)(1e5 + 123);
ll a[MAXN], b[MAXN], p[MAXN];
int main() {
    p[0]=1;
    for(ll i=1; i<=9; i++) p[i] = p[i - 1] * 10;

    ll n,k;
    cin >> n >> k;

    ll m = n/ k;
    for(ll i=0; i<m; i++) cin >> a[i];
    for(ll i=0; i<m; i++) cin >> b[i];

    ll ans = 1;
    for(ll i=0;i<m;i++){
        ll c1 = ((p[k]) - 1) / a[i] + 1;
        ll c2 = ((p[k - 1] * (b[i] + 1)) - 1) / a[i] + 1;
        ll c3 = ((p[k - 1] * b[i]) - 1) / a[i] + 1;
        if(b[i]==0)c3=0;
        ans= (ans * (c1 - c2 + c3) )%MOD;
    }
    cout << ans << endl;
    return 0;
}


/*
	*	Created By: 'Present_Sir'
	*	Created On: Tuesday 08 September 2020 01:43:19 PM IST
*/

#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define sz(v) ((int)v.size())
#define lgt(s) ((int)s.length())
#define int long long
using namespace std;

const int Mod = 1e9+7;

template <int mod>
struct ModInt {
    int x;
    ModInt() : x(0) {}
    ModInt(long long x_) {
        if ((x = x_ % mod + mod) >= mod) x -= mod;
    }
    ModInt& operator+=(ModInt rhs) {
        if ((x += rhs.x) >= mod) x -= mod;
        return *this;
    }
    ModInt& operator-=(ModInt rhs) {
        if ((x -= rhs.x) < 0) x += mod;
        return *this;
    }
    ModInt& operator*=(ModInt rhs) {
        x = (unsigned long long)x * rhs.x % mod;
        return *this;
    }
    ModInt& operator/=(ModInt rhs) {
        x = (unsigned long long)x * rhs.inv().x % mod;
        return *this;
    }

    ModInt operator-() const { return -x < 0 ? mod - x : -x; }
    ModInt operator+(ModInt rhs) const { return ModInt(*this) += rhs; }
    ModInt operator-(ModInt rhs) const { return ModInt(*this) -= rhs; }
    ModInt operator*(ModInt rhs) const { return ModInt(*this) *= rhs; }
    ModInt operator/(ModInt rhs) const { return ModInt(*this) /= rhs; }
    bool operator==(ModInt rhs) const { return x == rhs.x; }
    bool operator!=(ModInt rhs) const { return x != rhs.x; }
    ModInt inv() const { return pow(*this, mod - 2); }

    friend ostream& operator<<(ostream& s, ModInt<mod> a) {
        s << a.x;
        return s;
    }
    friend istream& operator>>(istream& s, ModInt<mod>& a) {
        s >> a.x;
        return s;
    }
};

using mint = ModInt<Mod>;
class Solver{
    public:
        void test(){
            //int t; cin>>t; for(int i=1; i<=t; ++i)
            {
                //cout<<"Case #"<<i<<": ";
                this->solve();
            }
        }
        void solve(){
            int n, k;
            cin>>n>>k;
            vector < int > pow(10,1);

            for(int i=1; i<n; ++i){
                pow[i] = pow[i-1]*10;
            }

            vector < int > mul(n/k);
            for(int i=0; i<n/k; ++i){
                cin>>mul[i];
            }

            mint ans = 1;

            for(int i=0; i<n/k; ++i){
                int b;
                cin>>b;
                int total = (pow[k]-1)/mul[i] + 1;
                int rem = (b*(pow[k-1]-1))%mul[i];
                if(rem==0) rem = mul[i];
                int remove = (pow[k-1]+rem-1)/mul[i];
                int val = total - remove;
                ans *= (val);
            }
            cout<<ans<<endl;
        }
};

int32_t main(){
    IOS;
    Solver S;
    S.test();
    return 0;
}


/*
	*	Created By: 'Present_Sir'
	*	Created On: Tuesday 08 September 2020 01:43:19 PM IST
*/

#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define sz(v) ((int)v.size())
#define lgt(s) ((int)s.length())
#define int long long
using namespace std;

const int Mod = 1e9+7;

template <int mod>
struct ModInt {
    int x;
    ModInt() : x(0) {}
    ModInt(long long x_) {
        if ((x = x_ % mod + mod) >= mod) x -= mod;
    }
    ModInt& operator+=(ModInt rhs) {
        if ((x += rhs.x) >= mod) x -= mod;
        return *this;
    }
    ModInt& operator-=(ModInt rhs) {
        if ((x -= rhs.x) < 0) x += mod;
        return *this;
    }
    ModInt& operator*=(ModInt rhs) {
        x = (unsigned long long)x * rhs.x % mod;
        return *this;
    }
    ModInt& operator/=(ModInt rhs) {
        x = (unsigned long long)x * rhs.inv().x % mod;
        return *this;
    }

    ModInt operator-() const { return -x < 0 ? mod - x : -x; }
    ModInt operator+(ModInt rhs) const { return ModInt(*this) += rhs; }
    ModInt operator-(ModInt rhs) const { return ModInt(*this) -= rhs; }
    ModInt operator*(ModInt rhs) const { return ModInt(*this) *= rhs; }
    ModInt operator/(ModInt rhs) const { return ModInt(*this) /= rhs; }
    bool operator==(ModInt rhs) const { return x == rhs.x; }
    bool operator!=(ModInt rhs) const { return x != rhs.x; }
    ModInt inv() const { return pow(*this, mod - 2); }

    friend ostream& operator<<(ostream& s, ModInt<mod> a) {
        s << a.x;
        return s;
    }
    friend istream& operator>>(istream& s, ModInt<mod>& a) {
        s >> a.x;
        return s;
    }
};

using mint = ModInt<Mod>;
class Solver{
    public:
        void test(){
            //int t; cin>>t; for(int i=1; i<=t; ++i)
            {
                //cout<<"Case #"<<i<<": ";
                this->solve();
            }
        }
        void solve(){
            int n, k;
            cin>>n>>k;
            vector < int > pow(11,1);

            for(int i=1; i<11; ++i){
                pow[i] = pow[i-1]*10;
            }

            vector < int > mul(n/k);
            for(int i=0; i<n/k; ++i){
                cin>>mul[i];
            }

            mint ans = 1;

            for(int i=0; i<n/k; ++i){
                int b;
                cin>>b;
                int total = (pow[k]-1)/mul[i] + 1;
                int rem = (b*(pow[k-1]))%mul[i];
                if(rem==0) rem = mul[i];
                int remove = (pow[k-1]+rem-1)/mul[i];
                int val = total - remove;
                ans *= (val);
                //cout<<val<<" "<<total<<" "<<rem<<endl;;
            }
            cout<<ans<<endl;
        }
};

int32_t main(){
    IOS;
    Solver S;
    S.test();
    return 0;
}


/*
	*	Created By: 'Present_Sir'
	*	Created On: Tuesday 08 September 2020 01:43:19 PM IST
*/

#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define sz(v) ((int)v.size())
#define lgt(s) ((int)s.length())
#define int long long
using namespace std;

const int Mod = 1e9+7;

template <int mod>
struct ModInt {
    int x;
    ModInt() : x(0) {}
    ModInt(long long x_) {
        if ((x = x_ % mod + mod) >= mod) x -= mod;
    }
    ModInt& operator+=(ModInt rhs) {
        if ((x += rhs.x) >= mod) x -= mod;
        return *this;
    }
    ModInt& operator-=(ModInt rhs) {
        if ((x -= rhs.x) < 0) x += mod;
        return *this;
    }
    ModInt& operator*=(ModInt rhs) {
        x = (unsigned long long)x * rhs.x % mod;
        return *this;
    }
    ModInt& operator/=(ModInt rhs) {
        x = (unsigned long long)x * rhs.inv().x % mod;
        return *this;
    }

    ModInt operator-() const { return -x < 0 ? mod - x : -x; }
    ModInt operator+(ModInt rhs) const { return ModInt(*this) += rhs; }
    ModInt operator-(ModInt rhs) const { return ModInt(*this) -= rhs; }
    ModInt operator*(ModInt rhs) const { return ModInt(*this) *= rhs; }
    ModInt operator/(ModInt rhs) const { return ModInt(*this) /= rhs; }
    bool operator==(ModInt rhs) const { return x == rhs.x; }
    bool operator!=(ModInt rhs) const { return x != rhs.x; }
    ModInt inv() const { return pow(*this, mod - 2); }

    friend ostream& operator<<(ostream& s, ModInt<mod> a) {
        s << a.x;
        return s;
    }
    friend istream& operator>>(istream& s, ModInt<mod>& a) {
        s >> a.x;
        return s;
    }
};

using mint = ModInt<Mod>;
class Solver{
    public:
        void test(){
            //int t; cin>>t; for(int i=1; i<=t; ++i)
            {
                //cout<<"Case #"<<i<<": ";
                this->solve();
            }
        }
        void solve(){
            int n, k;
            cin>>n>>k;
            vector < int > pow(10,1);

            for(int i=1; i<n; ++i){
                pow[i] = pow[i-1]*10;
            }

            vector < int > mul(n/k);
            for(int i=0; i<n/k; ++i){
                cin>>mul[i];
            }

            mint ans = 1;

            for(int i=0; i<n/k; ++i){
                int b;
                cin>>b;
                int total = (pow[k]-1)/mul[i] + 1;
                int rem = (b*(pow[k-1]))%mul[i];
                if(rem==0) rem = mul[i];
                int remove = (pow[k-1]+rem-1)/mul[i];
                int val = total - remove;
                ans *= (val);
                //cout<<val<<" ";
            }
            cout<<ans<<endl;
        }
};

int32_t main(){
    IOS;
    Solver S;
    S.test();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }

#define pb push_back
#define mp make_pair
#define cotu cout
#define itn int
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
#define setp(x) fixed << setprecision(x)
#define ordered_set tree<int , null_type,less<int >, rb_tree_tag,tree_order_statistics_node_update>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

const int inf = int(1e9);
const int mod = inf + 7;
const int N = 2e7 + 555; // TL MB
const double PI = acos(-1.0);
void mul(ll &x, ll y){
	x *= y;
	if(x >= mod) x %= mod;
}

void add(ll &x, ll y){
	x += y;
	if(x >= mod) x -= mod;
	if(x < 0) x += mod;
}
ll bp(ll a, ll n){
	ll r = 1;
	while(n){
		if(n & 1) mul(r, a);
		mul(a, a);
		n >>= 1;
	}
	return r;

}
void solve()
{
	ll n, k;
	cin >> n >> k;
	ll m = n / k;
	ll a[m], dp[m + 1];
	char b[m];
	rep(i, m) cin >> a[i];
	rep(i, m) cin >> b[i];
	dp[m] = 1;
	repr(i, m){
		dp[i] = 0;
		ll l = 1, r = 1e9, ans = 1;
		while(l <= r){
			ll m = l + r >> 1;
			ll x = m * a[i];
			if(sz(to_string(x)) >= k) ans = m, r = m - 1;
			else  l = m + 1;
		}
		ll pl = 1, pr = 1e9, ans2 = 1;
		while(pl <= pr){
			ll m = pl + pr >> 1;
			ll x = m * a[i];
			if(sz(to_string(x)) > k) pr = m - 1;
			else  ans2 = m, pl = m + 1;
		}
		ll tl = ans, tr = ans2, tp = -1;
		while(tl <= tr){
			ll m = tl + tr >> 1;
			ll x = m * a[i];
			if(to_string(x)[0] >= b[i]) tp = m, tr = m - 1;
			else tl = m + 1;
		}
		ll cl = ans, cr = ans2, cp = -1;
		while(cl <= cr){
			ll m = cl + cr >> 1;
			ll x = m * a[i];
			if(to_string(x)[0] > b[i]) cr = m - 1;
			else cp = m, cl = m + 1;
		}
 		dp[i] = (b[i] != '0' ? ans : 0) + ans2 - ans + 1 - ((~tp && ~cp) ? cp - tp + 1 : 0);
		mul(dp[i], dp[i + 1]);
	}
	cout << dp[0] << '\n';

}

 // a b c a b c a b c a b c

int main()
{
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
    Red;
  	// precalc();
  	int T = 1;
  	// cin >> T;
  	for(int i = 1; i <= T; ++i){
  		solve();
  	}
  	return 0;

}


#include<bits/stdc++.h>
using namespace std;
long long m=1e9+7;
int main()
{
	long long int n,k;
	cin>>n>>k;
	long long int A[n/k],B[n/k];
	for(int i=0;i<n/k;i++)cin>>A[i];
	for(int i=0;i<n/k;i++)cin>>B[i];
	long long int ans=1;
	long long int cnt;
	for(int i=0,j=0;i<n;i+=k,j++)
	{
	    cnt = int(((pow(10,k)-1)/A[j]))-int(((pow(10,k-1)*(B[j]+1))-1)/A[j]);

	    if(B[j]!=0)
	    {
	        cnt+= ((pow(10,(k-1))*B[j]-1))/A[j] +1;
	    }
	    //cout<<cnt<<endl;
	    ans=ans*cnt%m;
	}
	cout<<ans;

}


#include<bits/stdc++.h>
using namespace std;
long long m=1e9+7;
int main()
{
	int n,k;
	cin>>n>>k;
	int A[n/k],B[n/k];
	for(int i=0;i<n/k;i++)cin>>A[i];
	for(int i=0;i<n/k;i++)cin>>B[i];
	int ans=1;
	int cnt;
	for(int i=0,j=0;i<n;i+=k,j++)
	{
	    cnt = int(((pow(10,k)-1)/A[j]))-int(((pow(10,k-1)*(B[j]+1))-1)/A[j]);

	    if(B[j]!=0)
	    {
	        cnt+= int(((pow(10,(k-1))*B[j]-1))/A[j]) +1;
	    }
	    //cout<<cnt<<endl;
	    ans=ans*cnt%m;
	}
	cout<<ans;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,k;
	cin>>n>>k;
	int A[n/k],B[n/k];
	for(int i=0;i<n/k;i++)cin>>A[i];
	for(int i=0;i<n/k;i++)cin>>B[i];
	int ans=1;
	for(int i=0,j=0;i<n;i+=k,j++)
	{
		int cnt=0,number;
		for(int z=pow(10,k-1);z<pow(10,k);z++)
		{
			if(z%A[j]==0)
			{
				number=z;
				break;
			}
		}
		for(int z=number;z<pow(10,k);z+=A[j])
		{
			if(int(z/pow(10,k-1))!=B[j]) cnt++;
		}
		if(B[j]!=0) {
            cnt++;
            for(int z=A[j];z<pow(10,k-1);z+=A[j])
            cnt++;
		}

		//cout<<cnt<<endl;
		ans=ans*cnt;
	}
	cout<<ans;

}


#include <iostream>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <stdlib.h>

using namespace std;
// vector push_back push front top empty pop make_pair long long insert begin end
typedef long long ll;
typedef vector<int> vi;
typedef vector<pair <int,int> > vpi;
typedef vector<long long> vll;
typedef pair<int,int> pi;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define B begin()
#define rB rbegin()
#define E end()
#define rE rend()
#define Z size()
#define REP(i,a,b) for (int i = a; i < b; i++)
#define L length()
#define show(a) cerr << " *** " << a << endl;
#define show1(a) cerr << " /// " << a << endl;

int mod = 1e9+7;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n,k;
	cin >> n >> k;
	int x = n/k;
	vi a(x);
	vi b(x);
	REP(i,0,x)
		cin >> a[i];
	REP(i,0,x)
		cin >> b[i];
	ll ans = 1;
	for (int i = 0; i < x; i++)
	{
		int bd1= pow(10,k) -1;
		int bd2= b[i]*pow(10,k-1) -1;
		int bd3= (int)((b[i] + 1)*pow(10,k-1));
		ll tmp = 0;
		if (bd2 >= 0)
			tmp += bd2/a[i]+1;
		if (bd1 >= bd3)
			tmp += bd1/a[i] - bd3/a[i] + (bd3%a[i] == 0 ? 1 :0);
		ans *= tmp;
		ans %= mod;
	}
	cout << ans;
}


#include <iostream>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <stdlib.h>

using namespace std;
// vector push_back push front top empty pop make_pair long long insert begin end
typedef long long ll;
typedef vector<int> vi;
typedef vector<pair <int,int> > vpi;
typedef vector<long long> vll;
typedef pair<int,int> pi;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define B begin()
#define rB rbegin()
#define E end()
#define rE rend()
#define Z size()
#define REP(i,a,b) for (int i = a; i < b; i++)
#define L length()
#define show(a) cerr << " *** " << a << endl;
#define show1(a) cerr << " /// " << a << endl;

int mod = 1e9+7;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n,k;
	cin >> n >> k;
	int x = n/k;
	vi a(x);
	vi b(x);
	REP(i,0,x)
		cin >> a[i];
	REP(i,0,x)
		cin >> b[i];
	ll ans = 1;
	for (int i = 0; i < x; i++)
	{
		int bd1= pow(10,k) -1;
		int bd2= b[i]*pow(10,k-1) -1;
		int bd3= (b[i] + 1)*pow(10,k-1);
		ll tmp = 0;
		tmp += bd2/a[i]+1;
		tmp += bd1/a[i] - bd3/a[i] + (bd3%a[i] == 0 ? 1 :0);
		ans *= tmp;
		ans %= mod;
	}
	cout << ans;
}


#include <bits/stdc++.h>
using namespace std;
#define rout(a) {cout << a; return;}
#define bout(a) {cout << a; break;}
#define coout(a) {cout << a; continue;}
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef long long ll;
typedef pair<ll, ll> lii;

const int N = 100000;
ll a[N];
ll b[N];

ll ppow(ll b, ll exp) {
    ll ans = 1;
    while(exp--) {
        ans*=b;
    }

    return ans;
}

void solve() {
    ll n,k;
    cin >> n >> k;

    for(int i = 0;i< n/k; i++) {
        cin >> a[i];
    }

    for(int i = 0;i< n/k; i++) {
        cin >> b[i];
    }

    ll pp = ppow(10LL, k-1);
    ll mm = pp*10-1;
    ll aans = 1;
    for(int i = 0; i < n/k; i++) {
        ll ans = mm/a[i] + 1;

        ll mn = ceil(1.L*(pp*b[i])/a[i])*a[i];
        ll mx = pp*(b[i]+1)-1;
        if(mn <= mx)
            ans -= (mx-mn)/a[i]+1;

        aans = (aans * ans)%1000000007;
    }

    cout << aans;
}

int main() {
    //ios_base::sync_with_stdio(false);cin.tie(NULL);
    solve();

    getchar();getchar();
}


#include <bits/stdc++.h>

using namespace std;

#define INF int(1e9)
#define EPS 1e-9
#define MOD int(1e9 + 7)

int addMod(int a, int b) {
	return ((a % MOD) + (b % MOD)) % MOD;
}

int multiplyMod(int a, int b) {
	return (1LL * (a % MOD) * (b % MOD)) % MOD;
}

int power10[10];

int solve(int k, int a, int b) {
	int total = (power10[k] - 1) / a + 1;

	int sub = (power10[k - 1] - 1) / a;

	double subFraction = (power10[k - 1] - 1) * 1.0 / a - sub;

	int neededRem = (a - ((b * power10[k - 1]) % a)) % a;

	if(neededRem == 0 || neededRem - (subFraction * a) < EPS) {
		sub++;
	}

	return total - sub;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

	power10[0] = 1;
	for(int i = 1; i < 10; i++) {
		power10[i] = 10 * power10[i - 1];
	}

	int n, k;
	cin >> n >> k;
	int a[n / k], b[n / k];
	for(int i = 0; i < n / k; i++)
		cin >> a[i];
	for(int i = 0; i < n / k; i++)
		cin >> b[i];
	int ans = 1;
	for (int i = 0; i < n / k; i++) {
		ans = multiplyMod(ans, solve(k, a[i], b[i]));
	}
	cout << ans << '\n';
	return 0;
}


#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
int a[2000000],b[2000000] ;
int main()
{
    int n,k,nm=1 ;
    cin>>n>>k ;
    for(int i = 1 ; i <= n/k ; i++) cin>>a[i] ;
    for(int i = 1 ; i <= n/k ; i++) cin>>b[i] ;
    for(int i = 1 ; i < k ; i++) nm*=10 ;
  //  cout<<nm<<endl ; cout<<endl ;
    int fl=0,tr=0,ans=1 ;
    for(int i = 1 ; i <= n/k ; i++)
    {
        int p = a[i],st=nm,sm=0 ;
        fl=0 ; tr=0;
        while(st <= nm*10)
        {
            int q = st/p,r ;
            if(st%p==0) q-- ;
           // cout<<"st : "<<st<<" "<<" p : "<<p<<endl ;
           // cout<<"q :"<<q<<endl ;
           // cout<<"st/nm : "<<st/nm<<" b[i]+1 : "<<b[i]+1<<endl ;
            if(!fl) {if(st/nm!=b[i]+1)sm+=(q+1-tr) ; fl = 1 ;}
            else if(st/nm!=b[i]+1) sm+=(q-tr) ;
            tr=q ;
            st+=nm ;
           // cout<<sm<<" "<<tr<<endl ;
        }
       // cout<<sm<<endl ;cout<<endl ;
        ans=((ans%mod)*(sm%mod))%mod ;
    }
    cout<<ans<<endl ;
}


#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
ll a[2000000],b[2000000] ;
int main()
{
    ll n,k,nm=1 ;
    cin>>n>>k ;
    for(ll i = 1 ; i <= n/k ; i++) cin>>a[i] ;
    for(ll i = 1 ; i <= n/k ; i++) cin>>b[i] ;
    for(ll i = 1 ; i < k ; i++) nm*=10 ;
  //  cout<<nm<<endl ; cout<<endl ;
    ll fl=0,tr=0,ans=1 ;
    for(ll i = 1 ; i <= n/k ; i++)
    {
        ll p = a[i],st=nm,sm=0 ;
        fl=0 ; tr=0;
        while(st <= nm*10)
        {
            ll q = st/p,r ;
            if(st%p==0) q-- ;
           // cout<<"st : "<<st<<" "<<" p : "<<p<<endl ;
           // cout<<"q :"<<q<<endl ;
           // cout<<"st/nm : "<<st/nm<<" b[i]+1 : "<<b[i]+1<<endl ;
            if(!fl) {if(st/nm!=b[i]+1)sm+=(q+1-tr) ; fl = 1 ;}
            else if(st/nm!=b[i]+1) sm+=(q-tr) ;
            tr=q ;
            st+=nm ;
           // cout<<sm<<" "<<tr<<endl ;
        }
       // cout<<sm<<endl ;cout<<endl ;
        ans=((ans%mod)*(sm%mod))%mod ;
    }
    cout<<ans<<endl ;
}


#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
int a[2000000],b[2000000] ;
int fsz(int n)
{
    int t = 0 ;
    while(n){t++ ; n/=10 ;}
    return t ;
}
int main()
{
    int n,k,nm=1 ;
    cin>>n>>k ;
    for(int i = 1 ; i <= n/k ; i++) cin>>a[i] ;
    for(int i = 1 ; i <= n/k ; i++) cin>>b[i] ;
    for(int i = 1 ; i < k ; i++) nm*=10 ;
  //  cout<<nm<<endl ; cout<<endl ;
    int fl=0,tr=0,ans=1 ;
    for(int i = 1 ; i <= n/k ; i++)
    {
        int p = a[i],st=nm,sm=0 ;
        fl=0 ; tr=0;
        while(st <= nm*10)
        {
            int q = st/p,r ;
            if(st%p==0) q-- ;
           // cout<<"st : "<<st<<" "<<" p : "<<p<<endl ;
           // cout<<"q :"<<q<<endl ;
           // cout<<"st/nm : "<<st/nm<<" b[i]+1 : "<<b[i]+1<<endl ;
            if(!fl && st/nm!=b[i]+1) {sm+=(q+1-tr) ; fl = 1 ;}
            else if(st/nm!=b[i]+1) sm+=(q-tr) ;
            tr=q ;
            st+=nm ;
           // cout<<sm<<" "<<tr<<endl ;
        }
       // cout<<sm<<endl ;cout<<endl ;
        ans=((ans%mod)*(sm%mod))%mod ;
    }
    cout<<ans<<endl ;
}


#include<bits/stdc++.h>
using namespace std;
#define MAXN (int)(1e5 + 5)
#define MAXM (int)(1e2+5)
#define fr first
#define sd second
#define MP make_pair
#define pb push_back
#define ALL(v) v.begin(), v.end()
#define M0(a) memset(a, 0, sizeof(a))
#define M1(a) memset(a, -1, sizeof(a))
#define REP(i,n) for(int i = 0; i < int(n); i++)
#define REPN(i,n,m) for(int i = m; i <= int(n); i++)
#define RREP(i,n) for(int i = int(n-1); i >= 0; i--)
#define RREPN(i, n, m) for(int i = n; i >= (int)m; i--)
typedef long long ll;
typedef double db;
typedef long double ld;
const ll INF= int(1e11 + 7);
const ll MOD = ll(1e9 + 7);
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pii, pii> ppii;
template<typename T, typename U> inline void AMIN(T &x, U y){ if(x > y) x = y;}
template<typename T, typename U> inline void AMAX(T &x, U y){ if(x < y) x = y;}
int  A[MAXN], B[MAXN];

int ck(int a, int b) {

        int f;
        while(a)
                f = a % 10, a /= 10;
        return f == b;
}

int main() {
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        int n, k;
        cin >> n >> k;

        REP(i, n / k)
                cin >> A[i];

        REP(i, n / k)
                cin >> B[i];

        ll ans = 1, p;
        vector<ll> calc;

        p = 1;
        REP(i, k)
                p = 10 * p;

        REP(i, n / k) {

                ll a = A[i], b = B[i];

                p /= 10;
                ll y = 0, x = b * p;
                ll m = a - x % a;

                y = (p - 1) / a;
                if((p - 1) % a >= m % a)
                        y++;

                p *= 10;
                y = (p - 1) / a - y;
                calc.pb(y);
        }

        ans = 1LL;
        for(ll u : calc) {

                ans = (ans + (ans * u)) % MOD;
        }

        cout << ans << endl;
        return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N=1e5+5;
const int MOD=1e9+7;

int n, k, ans=1;
int a[N], b[N], mx[N], pw[N];

int32_t main()
{
	IOS;
	pw[0]=1;
	for(int i=1;i<=10;i++)
	{
		pw[i]=pw[i-1]*10;
		mx[i]=pw[i]-1;
	}
	cin>>n>>k;
	for(int i=1;i<=n/k;i++)
		cin>>a[i];
	for(int i=1;i<=n/k;i++)
		cin>>b[i];
	for(int i=1;i<=n/k;i++)
	{
		int total=1 + mx[k]/a[i];
		int remainder=(b[i]*pw[k-1])%a[i];
		if(remainder==0)
			remainder+=a[i];
		int remove=(mx[k-1]+remainder)/a[i];
		total-=remove;
		total+=MOD;
		total%=MOD;
		ans*=total;
		ans%=MOD;
	}
	cout<<ans;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

const int mod = 1e9 + 7;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector <int> pw = {1};
    while (pw.size() < 8) {
        pw.push_back(pw.back() * 10);
    }
    vector <int> a(n / k), b(n / k);
    for (int i = 0; i < n / k; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n / k; i++) {
        cin >> b[i];
    }
    ll ans = 1;
    for (int i = 0; i < n / k; i++) {
        ll up = pw[k] - 1;
        ll dw = pw[k - 1] - 1;
        ll cnt = up / a[i] + 1;
        if (b[i] == 0) {
            cnt--;
            ll up = pw[k - 1] - 1;
            cnt -= up / a[i];
        } else {
            ll nw_cnt = 0;
            up = pw[k - 1] * (b[i] + 1) - 1;
            dw = pw[k - 1] * b[i] - 1;
            nw_cnt += up / a[i];
            nw_cnt -= dw / a[i];
            cnt -= nw_cnt;
        }
        cnt %= mod;
        ans *= cnt;
        ans %= mod;
    }
    cout << ans << '\n';
    return 0;
}