#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  long long res = 1;
  int n, k;
  cin >> n >> k;
  vector<long long> a(n / k), b(n / k);
  for (int i = (0); i < n / k; i++) cin >> a[i];
  for (int i = (0); i < n / k; i++) cin >> b[i];
  for (int i = (0); i < n / k; i++) {
    long long maxi = (long long)pow(10, k), mini = b[i] * maxi / 10;
    if (mini % a[i]) mini += a[i] - mini % a[i];
    long long te = ((b[i] + 1) * (maxi / 10) - 1 - mini);
    if (te < 0)
      te = 0;
    else
      te = te / a[i] + 1;
    res *= (((maxi + a[i] - 1) / a[i]) - te);
    res %= 1000000007;
  }
  cout << res << "\n";
}
