#include <bits/stdc++.h>
using namespace std;
long long modx(long long Base, long long exponent) {
  long long ans = 1;
  if (Base == 1) return Base;
  while (exponent) {
    if (exponent & 1) ans = (ans * Base) % 1000000007;
    Base = (Base * Base) % 1000000007;
    exponent = exponent >> 1;
  }
  return ans;
}
long long inmodx(long long num) { return (modx(num, 1000000005LL)); }
bool cmp() { return false; }
long long a[1000009], b[1000009], p[15];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k, i;
  long long ans = 1, x, y, z;
  cin >> n >> k;
  for (i = (1); i < ((n / k) + 1); i++) cin >> a[i];
  for (i = (1); i < ((n / k) + 1); i++) cin >> b[i];
  p[0] = 1LL;
  for (i = (1); i < (k + 1); i++) p[i] = p[i - 1] * 10LL;
  for (i = (1); i < ((n / k) + 1); i++) {
    x = (p[k] - 1) / a[i] + 1LL;
    y = a[i] - (p[k - 1] * b[i]) % a[i];
    z = (p[k - 1] - 1) / a[i];
    if ((p[k - 1] - 1) % a[i] >= y || y == a[i]) z++;
    x -= z;
    ans = (ans * x) % 1000000007;
  }
  cout << ans;
  return 0;
}
