#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
int a[223000], b[223000];
int n, p, k;
long long js(int i) {
  long long ans = (p - 1) / a[i] + 1;
  if (b[i] == 0) return ans - (p / 10 - 1) / a[i] - 1;
  return ans - ((((b[i] + 1) * (p / 10) - 1) / a[i]) -
                ((b[i] * (p / 10) - 1) / a[i]));
}
int main() {
  p = 1;
  cin >> n >> k;
  for (int i = 1; i <= k; i++) p = p * 10;
  for (int i = 1; i <= n / k; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n / k; i++) scanf("%d", &b[i]);
  long long ans = 1;
  for (int i = 1; i <= n / k; i++) {
    ans = (ans * js(i)) % mod;
  }
  cout << ans << endl;
  return 0;
}
