#include <bits/stdc++.h>
using namespace std;
void dbg_out() { cerr << "\b\b]\n"; }
template <typename Head, typename... Tail>
void dbg_out(Head H, Tail... T) {
  cerr << H << ", ";
  dbg_out(T...);
}
const int mod = 1e9 + 7;
long long power(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return res;
}
long long modMul(long long a, long long b) { return a * b % mod; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, k;
  cin >> n >> k;
  vector<int> A(n / k), B(n / k);
  for (int &i : A) cin >> i;
  for (int &i : B) cin >> i;
  long long ans = 1;
  long long tens = power(10, k - 1);
  for (int i = 0; i < n / k; ++i) {
    long long tot = (tens * 10 - 1) / A[i] + 1;
    long long lo = B[i] * tens;
    long long hi = B[i] * tens + tens - 1;
    long long invalid = hi / A[i] - lo / A[i] + (lo % A[i] == 0);
    tot -= invalid;
    ans = modMul(ans, tot);
  }
  cout << ans;
  return 0;
}
