#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int a[100010], b[100010];
int main() {
  int n, k, m;
  scanf("%d%d", &n, &k);
  int val = 1;
  for (int i = 0; i < k; i++) val *= 10;
  m = n / k;
  for (int i = 0; i < m; i++) scanf("%d", &a[i]);
  for (int i = 0; i < m; i++) scanf("%d", &b[i]);
  long long ans = 1;
  for (int i = 0; i < m; i++) {
    int t = (val - (val % a[i])) / a[i];
    if (val % a[i]) t++;
    int num = (a[i] - (val / 10 * b[i]) % a[i]) % a[i];
    if ((val / 10) <= num) {
      ans = ans * t % mod;
      continue;
    }
    int tt = ((val / 10 - num) - ((val / 10 - num) % a[i])) / a[i];
    if ((val / 10 - num) % a[i]) tt++;
    ans = ans * (t - tt) % mod;
  }
  printf("%d\n", ans);
  return 0;
}
