#include <bits/stdc++.h>
using namespace std;
const int MOD7 = 1e9 + 7;
const int MOD9 = 1e9 + 9;
const double EPS = 1e-9;
long long int gcd(long long int a, long long int b) {
  return b == 0 ? a : gcd(b, a % b);
}
int toint(const string &s) {
  stringstream second;
  second << s;
  int x;
  second >> x;
  return x;
}
long long int mpow(long long int a, long long int n, int mod) {
  long long int ret = 1;
  long long int b = a;
  while (n) {
    if (n & 1) ret = (ret * b) % mod;
    b = (b * b) % mod;
    n >>= 1;
  }
  return (long long int)ret;
}
struct cmp {
  bool operator()(pair<pair<int, int>, int> a, pair<pair<int, int>, int> b) {
    if (a.first.first < b.first.first)
      return true;
    else if (a.first.first == b.first.first)
      return a.first.second < b.first.second;
    return false;
  }
};
int arra[100005] = {0}, arrb[100005] = {0};
int main() {
  int tc;
  tc = 1;
  int i, n, m, k, x1, x2, j;
  long long base = 0, aux1 = 0, aux2 = 0, ans = 1;
  while (tc--) {
    scanf("%d", &n);
    scanf("%d", &k);
    for (i = 0; i < n / k; i++) scanf("%d", &arra[i]);
    for (i = 0; i < n / k; i++) scanf("%d", &arrb[i]);
    for (i = 0; i < k; i++) base = base * 10 + 9;
    for (i = 0; i < n / k; i++) {
      x1 = arra[i];
      x2 = arrb[i];
      aux1 = aux2 = x2;
      for (j = 0; j < k - 1; j++) {
        aux1 = aux1 * 10 + 9;
        aux2 = aux2 * 10;
      }
      if (aux1 <= base && aux2 <= base)
        ans = (ans *
               (((base / x1 + 1) - (aux1 / x1) + aux2 / x1 -
                 (aux2 % x1 == 0 ? 1 : 0))) %
               MOD7) %
              MOD7;
      else
        ans = (ans * ((base / x1 + 1) % MOD7)) % MOD7;
    }
    printf("%lld\n", ans);
  }
  return 0;
}
