#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007LL;
long long N, k, cat, pk, lb, rb;
long long nr[100005];
long long a[100005], b[100005];
long long sol;
int cautbin1(long long x, long long lm, long long lM) {
  long long l = lm - 1, r = lM + 1;
  while (r - l > 1) {
    long long mid = (l + r) / 2;
    if (x * mid > lM)
      r = mid;
    else
      l = mid;
  }
  if (l == lm - 1) return lm;
  return l;
}
int cautbin2(long long x, long long lm, long long lM) {
  long long l = lm - 1, r = lM + 1;
  while (r - l > 1) {
    long long mid = (l + r) / 2;
    if (x * mid >= lM)
      r = mid;
    else
      l = mid;
  }
  if (r == lM + 1) return lM;
  return r;
}
int main() {
  cin >> N >> k;
  cat = N / k;
  for (int i = 1; i <= cat; ++i) cin >> a[i];
  for (int i = 1; i <= cat; ++i) cin >> b[i];
  pk = 1;
  for (int i = 1; i <= k; ++i) pk *= 10;
  pk -= 1;
  for (int i = 1; i <= cat; ++i) {
    lb = 1;
    for (int i = 1; i <= k - 1; ++i) lb *= 10;
    lb *= b[i];
    lb -= 1;
    rb = 1;
    for (int i = 1; i <= k - 1; ++i) rb *= 10;
    rb *= (b[i] + 1);
    if (b[i] != 0) nr[i] = 1;
    nr[i] = (nr[i] + cautbin1(a[i], 0, lb)) % MOD;
    nr[i] = (nr[i] + (cautbin1(a[i], 0, pk) - cautbin2(a[i], 0, rb) + 1)) % MOD;
  }
  sol = nr[1];
  for (int i = 2; i <= cat; ++i) sol = (sol * nr[i]) % MOD;
  cout << sol << '\n';
  return 0;
}
