#include <bits/stdc++.h>
using namespace std;
int a[100005], b[100005];
int main() {
  ios_base::sync_with_stdio(false);
  int n, k, i, inc;
  long long maxval, t1, t2, t3;
  cin >> n >> k;
  t1 = 0;
  maxval = 0;
  while (t1 < k) {
    maxval *= 10;
    maxval += 9;
    t1++;
  }
  inc = 1;
  long long tmp = 1;
  while (inc < k) {
    tmp *= 10;
    inc++;
  }
  for (i = 0; i < (n / k); i++) cin >> a[i];
  for (i = 0; i < (n / k); i++) cin >> b[i];
  long long ans = 1;
  for (i = 0; i < (n / k); i++) {
    t1 = (maxval / a[i]) + 1;
    t2 = (b[i] * tmp);
    t3 = ((b[i] + 1) * tmp) - 1;
    t1 -= ((t3 / a[i]) - (t2 / a[i]));
    if (t2 % a[i] == 0) t1--;
    ans *= t1;
    ans %= 1000000007;
  }
  cout << ans << endl;
  return 0;
}
