#include <bits/stdc++.h>
using namespace std;
int poss(int a, int b, int length);
int power(int a, int b);
int main() {
  ios_base::sync_with_stdio(0);
  int n, k;
  cin >> n >> k;
  int m = n / k;
  long long prod = 1;
  vector<int> A(m);
  vector<int> B(m);
  for (int i = 0; i < m; i++) {
    cin >> A[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> B[i];
    prod = (prod * poss(A[i], B[i], k)) % (power(10, 9) + 7);
  }
  cout << prod << endl;
  return 0;
}
int power(int a, int b) {
  int g = 1;
  for (int i = 0; i < b; i++) {
    g = g * a;
  }
  return g;
}
int poss(int a, int b, int length) {
  int g = ((power(10, length) - 1) - (power(10, length) - 1) % a) / a + 1;
  if (b == 0) {
    g -=
        ((power(10, length - 1) - 1) - (power(10, length - 1) - 1) % a) / a + 1;
  } else {
    int b1 = (power(10, length - 1)) % a;
    if ((((b + 1) * (power(10, length - 1))) - 1) % a < b1)
      g -= (power(10, length - 1)) / a + 1;
    else
      g -= (power(10, length - 1)) / a;
  }
  return g % (power(10, 9) + 7);
}
