#include <bits/stdc++.h>
using namespace std;
template <class T>
bool uax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool uin(T& a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(nullptr);
  long long n, k;
  cin >> n >> k;
  long long tenk = 1, tenk_1 = 1;
  for (int i = 0; i < (int)(k); ++i) tenk *= 10;
  for (int i = 0; i < (int)(k - 1); ++i) tenk_1 *= 10;
  vector<long long> a(n / k), b(n / k);
  for (int i = 0; i < (int)(n / k); ++i) {
    cin >> a[i];
  }
  for (int i = 0; i < (int)(n / k); ++i) {
    cin >> b[i];
  }
  const long long M = 1e9 + 7;
  long long ans = 1;
  long long sum = 0;
  for (int i = 0; i < (int)(n / k); ++i) {
    long long cnt1 = (tenk - 1) / a[i] + 1;
    long long cnt2 = (tenk_1 - 1) / a[i] + 1;
    sum = 0;
    if (b[i] == 0) {
      sum += cnt1 - cnt2;
    } else {
      long long l = tenk_1 * b[i], r = l + tenk_1 - 1;
      long long c2 = r / a[i], c1 = l / a[i];
      if (c1 * a[i] < l) c1++;
      sum += cnt1;
      sum -= c2 - c1 + 1;
    }
    ans = (ans * sum) % M;
  }
  cout << ans;
  return 0;
}
