#include <bits/stdc++.h>
using namespace std;
long long power(long long a) {
  long long prod = 1;
  while (a--) prod *= 10;
  return prod;
}
int main() {
  long long n, k;
  cin >> n >> k;
  long long bal = n / k;
  long long a[bal];
  long long b[bal];
  for (long long i = 0; i < bal; i++) scanf("%I64d", &a[i]);
  for (long long i = 0; i < bal; i++) scanf("%I64d", &b[i]);
  long long ans = 1;
  long long f = power(k);
  for (long long i = 0; i < bal; i++) {
    long long ish = f / a[i];
    if (f % a[i] != 0) ish++;
    long long fi, se;
    long long p = power(k - 1);
    fi = b[i] * p / a[i];
    if ((b[i] * p) % a[i] != 0) fi++;
    se = (b[i] + 1) * p / a[i];
    if (((b[i] + 1) * p) % a[i] == 0) se--;
    ish = ish - (se - fi + 1);
    ans = ans * ish;
    ans = ans % 1000000007;
  }
  cout << ans;
}
