#include <bits/stdc++.h>
using namespace std;
const int modulo = 1000 * 1000 * 1000 + 7;
int main() {
  ios_base::sync_with_stdio(0);
  long long cnt = 0;
  long long n, m;
  long long ten = 1;
  cin >> n >> m;
  for (long long i = 0; i < min(n, m); ++i) ten *= 10;
  long long k = n / m;
  vector<long long> a(k), b(k);
  for (long long i = 0; i < k; ++i) cin >> a[i];
  for (long long i = 0; i < k; ++i) cin >> b[i];
  long long ans = 1;
  for (long long i = 0; i < k; ++i) {
    long long cur_ans = 0;
    cur_ans += (ten - 1) / a[i];
    long long c = (ten / 10 * (b[i] + 1) - 1) / a[i];
    long long d = b[i] ? (ten / 10 * b[i] - 1) / a[i] : 0;
    cur_ans += modulo;
    cur_ans += d;
    cur_ans -= c;
    cur_ans %= modulo;
    if (b[i]) cur_ans++;
    cur_ans %= modulo;
    ans = (ans * cur_ans) % modulo;
  }
  cout << ans << endl;
  return 0;
}
