#include <bits/stdc++.h>
using namespace std;
const long long modul = 1000000007;
const long long max_n = 100100;
int n, k;
long long a[max_n];
long long b[max_n];
long long up[max_n] = {1,      10,      100,      1000,      10000,
                       100000, 1000000, 10000000, 100000000, 1000000000};
long long ans = 1;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  while (cin >> n >> k && n && k) {
    ans = 1;
    int len = n / k;
    for (int i = 0; i < len; i++) {
      cin >> a[i];
    }
    for (int i = 0; i < len; i++) {
      cin >> b[i];
    }
    for (int i = 0; i < len; i++) {
      int cnt = 0;
      int all = (up[k] - 1) / a[i] + 1;
      cnt = (up[k - 1] * (b[i] + 1) - 1) / a[i] - up[k - 1] * b[i] / a[i];
      if ((up[k - 1] * b[i]) % a[i] == 0) {
        cnt++;
      }
      ans = ans * (all - cnt) % modul;
    }
    cout << ans << endl;
  }
  return 0;
}
