#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
long long MOD = 1000000007;
int n, k, ndk;
long long a[MAXN];
long long b[MAXN];
long long cnt[MAXN];
int Trans(int nn) {
  int kk = k;
  while (--kk) nn *= 10;
  return nn;
}
long long Solve(int nn, int left, int right) {
  int moreleft = (left / a[nn]) * a[nn];
  int lessright = (right / a[nn]) * a[nn];
  long long ct = (lessright - moreleft) / a[nn] + 1;
  if (moreleft < left) ct--;
  return ct;
}
void Cal(int nn) {
  for (int i = 0; i < 10; i++) {
    if (i != b[nn]) cnt[nn] += Solve(nn, Trans(i), Trans(i + 1) - 1);
  }
  return;
}
long long Getans() {
  long long ans = 1;
  for (int i = 0; i < ndk; i++) {
    ans *= cnt[i];
    ans %= MOD;
  }
  return ans;
}
int main() {
  while (scanf("%d%d", &n, &k) != EOF) {
    ndk = n / k;
    for (int i = 0; i < ndk; i++) cin >> a[i];
    for (int i = 0; i < ndk; i++) cin >> b[i];
    for (int i = 0; i < ndk; i++) cnt[i] = 0;
    for (int i = 0; i < ndk; i++) Cal(i);
    cout << Getans() << endl;
  }
  return 0;
}
