#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k;
  cin >> n >> k;
  long long ns = n / k;
  long long a[ns], b[ns];
  for (long long i = 0; i < ns; i++) {
    cin >> a[i];
  }
  for (long long i = 0; i < ns; i++) {
    cin >> b[i];
  }
  long long pp = 1;
  for (long long i = 1; i <= k; i++) pp = pp * 10;
  long long qq = pp / 10;
  if (qq == 0) qq = 1;
  vector<long long> v;
  long long ct = 0;
  for (long long i = 0; i < ns; i++) {
    ct = 0;
    ct = (1.0 * (pp - 1) / a[i]) + 1;
    long long ct1;
    ct1 = (qq * b[i]) % a[i];
    long long ct2 = (a[i] - ct1) % a[i];
    long long rr = (qq - 1 - ct2);
    long long ct4;
    if (rr >= 0)
      ct4 = (rr * 1.0 / a[i]) + 1;
    else {
      ct4 = 0;
    }
    if ((ct - ct4) >= 0) v.push_back(ct - ct4);
  }
  long long ans = 1;
  long long MOD = 1000000007;
  for (long long i = 0; i < v.size(); i++) {
    ans = (ans * v[i]) % MOD;
    ans = (ans + MOD) % MOD;
  }
  ans = ans % MOD;
  cout << ans << endl;
  return 0;
}
