#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T _sq(T a) {
  return a * a;
}
template <class T>
inline T _sqrt(T a) {
  return (T)sqrt((double)a);
}
template <class T, class X>
inline T _pow(T a, X y) {
  T z = 1;
  for (int i = 1; i <= y; i++) {
    z *= a;
  }
  return z;
}
template <class T>
inline T _gcd(T a, T b) {
  a = abs(a);
  b = abs(b);
  if (!b) return a;
  return _gcd(b, a % b);
}
template <class T>
inline T _lcm(T a, T b) {
  a = abs(a);
  b = abs(b);
  return (a / _gcd(a, b)) * b;
}
template <class T>
inline T _extended(T a, T b, T &x, T &y) {
  a = abs(a);
  b = abs(b);
  T g, x1, y1;
  if (!b) {
    x = 1;
    y = 0;
    g = a;
    return g;
  }
  g = _extended(b, a % b, x1, y1);
  x = y1;
  y = x1 - (a / b) * y1;
  return g;
}
template <class T, class X>
inline bool getbit(T a, X i) {
  T t = 1;
  return ((a & (t << i)) > 0);
}
template <class T, class X>
inline T setbit(T a, X i) {
  T t = 1;
  return (a | (t << i));
}
template <class T, class X>
inline T resetbit(T a, X i) {
  T t = 1;
  return (a & (~(t << i)));
}
template <class T, class X>
inline T togglebit(T a, X i) {
  T t = 1;
  return (a ^ (t << i));
}
template <class T>
void pv(T v) {
  for (int i = 0; i < ((int)v.size()); i++) cout << v[i] << " ";
  cout << endl;
}
template <class T, class X>
inline T _bigmod(T n, X m) {
  unsigned long long ret = 1, a = n % 1000000007ll;
  while (m) {
    if (m & 1) ret = (ret * a) % 1000000007ll;
    m >>= 1;
    a = (a * a) % 1000000007ll;
  }
  ret %= 1000000007ll;
  return (T)ret;
}
template <class T>
inline T _modinv(T n) {
  return _bigmod(n, 1000000007ll - 2);
}
long long n, k, a[(200000 + 3)], b[(200000 + 3)];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> k;
  long long m = n / k;
  for (int i = 1; i <= m; i++) {
    cin >> a[i];
  }
  long long ans = 1;
  for (int i = 1; i <= m; i++) {
    cin >> b[i];
    long long w = 0;
    if (k == 1) {
      for (int j = 0; j <= 9; j++) {
        w += (j != b[i] && j % a[i] == 0);
        if (w >= 1000000007ll) w -= 1000000007ll;
      }
    } else {
      long long h = 0, g = 0, e = b[i], f = b[i];
      for (int j = 1; j <= k; j++) {
        h = h * 10 + 9;
        if (j < k) e = e * 10 + 9;
        if (j < k) f = f * 10 + 0;
      }
      g = h / 10;
      f--;
      if (b[i] == 0) {
        w += (h / a[i]) - (g / a[i]);
      } else {
        w += 1ll + (h / a[i]) - (e / a[i]) + (f / a[i]);
      }
    }
    w = ((w % 1000000007ll) + 1000000007ll) % 1000000007ll;
    ans *= w;
    if (ans >= 1000000007ll) ans %= 1000000007ll;
  }
  cout << ans << endl;
  return 0;
}
