#include <bits/stdc++.h>
const int maxn = 100005;
long long a[maxn], b[maxn];
const long long mod = 1e9 + 7;
long long sum[maxn];
long long num[20];
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  int m = n / k;
  int i, j;
  for (i = 0; i < m; i++) {
    scanf("%lld", &a[i]);
  }
  for (i = 0; i < m; i++) {
    scanf("%lld", &b[i]);
  }
  num[0] = 0;
  num[1] = 9;
  for (i = 2; i <= 9; i++) num[i] = num[i - 1] * 10 + 9;
  for (i = 0; i < m; i++) {
    long long x = num[k] / a[i] + 1;
    if (b[i] > 0 && b[i] <= 9) {
      long long xx = b[i], yy = b[i];
      for (j = 1; j < k; j++) xx = xx * 10 + 9, yy = yy * 10;
      x -= xx / a[i] - (yy - 1) / a[i];
    } else if (b[i] == 0) {
      long long xx = b[i];
      for (j = 1; j < k; j++) xx = xx * 10 + 9;
      x -= xx / a[i] + 1;
    }
    sum[i] = x;
  }
  long long ans = 1;
  for (i = 0; i < m; i++) {
    ans = ans * sum[i] % mod;
  }
  printf("%lld\n", ans);
  return 0;
}
