#include <bits/stdc++.h>
using namespace std;
int mulmod(int a, int b) {
  if (b == 0) return 1;
  if (b == 1) return a;
  int c = mulmod(a, b / 2);
  c = (c * c);
  if (b % 2) c = (c * a);
  return c;
}
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n / k);
  vector<int> 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];
  }
  long long ans = 1;
  long long MOD = 1e9 + 7;
  for (int i = 0; i < n / k; i++) {
    int d = b[i];
    int totalCount = (mulmod(10, k) - 1) / a[i] + 1;
    int largestNo = (mulmod(10, k) - 1);
    int currentNo = b[i] * mulmod(10, k - 1);
    currentNo %= a[i];
    int reqdRem = (a[i] - currentNo) % a[i];
    int lessCount = (mulmod(10, k - 1) - 1) / a[i];
    if ((largestNo / 10) % a[i] >= reqdRem) lessCount++;
    totalCount -= lessCount;
    ans = (ans * totalCount) % MOD;
  }
  cout << ans << endl;
}
