#include <bits/stdc++.h>
using namespace std;
long long a[100005], b[100005];
long long power(long long base, long long expo) {
  if (expo == 0) return 1;
  long long ret = 1;
  while (expo) {
    if (expo & 1) {
      ret *= base;
    }
    base *= base;
    expo >>= 1;
  }
  return ret;
}
long long num(long long k, long long A, long long m) {
  long long mx = power(10, k) - 1;
  long long ret;
  mx -= m;
  if (mx >= 0)
    ret = ((mx / A) + 1);
  else
    ret = 0;
  return ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  long long n, k;
  cin >> n >> k;
  long long t = n / k;
  for (int i = 1; i <= t; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= t; i++) {
    cin >> b[i];
  }
  if (k == 1) {
    long long ans = 1;
    for (int i = 1; i <= t; i++) {
      long long cnt = 0;
      for (int j = 0; j <= 9; j++) {
        if (j != b[i]) {
          if (j % a[i] == 0) cnt++;
        }
      }
      ans *= cnt;
      ans %= 1000000007;
    }
    cout << ans;
    return 0;
  }
  long long ans = 1;
  for (int i = 1; i <= t; i++) {
    long long sum = 0;
    for (int j = 0; j <= 9; j++) {
      if (j != b[i]) {
        long long N = (long long)j * power(10, k - 1);
        long long X = N % a[i];
        sum += num(k - 1, a[i], (a[i] - X) % a[i]);
      }
    }
    ans *= sum;
    ans %= 1000000007;
  }
  cout << ans << endl;
}
