#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1e9 + 7;
int main() {
  long long int n, k, A[100005], B[100005], i, p, sum, v, bp, ans, t, t1, t2, q;
  cin >> n >> k;
  for (i = 1; i <= n / k; i++) cin >> A[i];
  for (i = 1; i <= n / k; i++) cin >> B[i];
  p = 9, sum = 0;
  for (i = 1; i <= k; i++) {
    sum = sum + p;
    p = p * 10;
  }
  v = sum / 10;
  bp = sum;
  ans = 1;
  for (i = 1; i <= n / k; i++) {
    bp = sum;
    if (B[i] != 0) {
      t = bp / A[i];
      if (B[i] == 1)
        q = v;
      else {
        q = (B[i] - 1) * pow(10, k - 1);
        q = q + v;
      }
      t1 = q / A[i];
      q = B[i] * pow(10, k - 1);
      q = q + v;
      t2 = q / A[i];
      t = t - (t2 - t1);
      t++;
    } else {
      t = bp / A[i];
      t1 = v / A[i];
      t = t - t1;
    }
    ans = ((ans % MOD) * (t % MOD)) % MOD;
  }
  cout << ans;
  return 0;
}
