#include <bits/stdc++.h>
using namespace std;
long long p10[30];
int main() {
  ios_base::sync_with_stdio(false);
  p10[0] = 1;
  for (int i = 1; i < 20; ++i) {
    p10[i] = p10[i - 1] * 10LL;
  }
  long long n, k;
  cin >> n >> k;
  long long a[100005], b[100005];
  long long div = n / k;
  for (int i = 0; i < div; ++i) {
    cin >> a[i];
  }
  for (int i = 0; i < div; ++i) {
    cin >> b[i];
  }
  long long ans = 1;
  const long long MOD = 1000000007;
  for (int i = 0; i < div; ++i) {
    long long total = (p10[k] - 1LL) / a[i] + 1;
    long long first = (b[i] * p10[k - 1] + a[i] - 1) / a[i];
    long long last = ((b[i] + 1) * p10[k - 1] - 1) / a[i];
    ans = (ans * (total - (last - first + 1))) % MOD;
  }
  cout << ans;
  return 0;
}
