#include <bits/stdc++.h>
using namespace std;
long long BigMod(long long B, long long P, long long M) {
  long long R = 1;
  while (P > 0) {
    if (P % 2 == 1) {
      R = (R * B) % M;
    }
    P /= 2;
    B = (B * B) % M;
  }
  return R;
}
template <class T1>
void deb(T1 e1) {
  cout << e1 << endl;
}
template <class T1, class T2>
void deb(T1 e1, T2 e2) {
  cout << e1 << " " << e2 << endl;
}
template <class T1, class T2, class T3>
void deb(T1 e1, T2 e2, T3 e3) {
  cout << e1 << " " << e2 << " " << e3 << endl;
}
template <class T1, class T2, class T3, class T4>
void deb(T1 e1, T2 e2, T3 e3, T4 e4) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << endl;
}
template <class T1, class T2, class T3, class T4, class T5>
void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << " " << e5 << endl;
}
template <class T1, class T2, class T3, class T4, class T5, class T6>
void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5, T6 e6) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << " " << e5 << " " << e6
       << endl;
}
const long long MOD = 1000000007ll;
const int MAX = 100009;
char str[MAX];
long long a[MAX];
long long b[MAX];
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  int t = n / k;
  for (int i = 0; i < t; i++) {
    scanf("%I64d", &a[i]);
  }
  for (int i = 0; i < t; i++) {
    scanf("%I64d", &b[i]);
  }
  long long l = 1, r = 1;
  for (int i = 0; i < k; i++) l *= 10ll;
  for (int i = 1; i < k; i++) r *= 10ll;
  l--;
  r--;
  long long res = 0, tot, md1, md2, tmp, md3, md4;
  for (int i = 0; i < t; i++) {
    tot = l / a[i] + 1;
    md1 = l % a[i];
    md2 = b[i] % a[i];
    for (int j = 1; j < k; j++) {
      md2 *= 10ll;
      md2 %= a[i];
    }
    tmp = r / a[i] + 1;
    md3 = (a[i] - md2) % a[i];
    md4 = r % a[i];
    if (md3 > md4) tmp--;
    tot -= tmp;
    if (i) {
      res *= tot;
      res %= MOD;
    } else
      res = tot % MOD;
  }
  printf("%I64d\n", res);
  return 0;
}
