#include <bits/stdc++.h>
using namespace std;
long long fun(long long x, long long a) {
  long long ch1;
  ch1 = x / a + 1;
  return ch1;
}
long long fu(long long st, long long dr, long long kak) {
  long long ch = st, i;
  for (i = 0; i < dr; i++) ch = ch * 10 + kak;
  return ch;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long mo = 1e9 + 7;
  long long n, m, i, j, a;
  cin >> n >> m;
  vector<long long> v1, v2, v3, v4;
  for (i = 0; i < n / m; i++) {
    cin >> a;
    v1.push_back(a);
  }
  long long g1 = 1, g2 = 1;
  for (j = 0; j < m - 1; j++) {
    g2 = g2 * 10;
    g1 = g1 * 10 + 9;
  }
  for (i = 0; i < n / m; i++) {
    cin >> a;
    v4.push_back(a);
    v2.push_back(g1 + (g2 * (a - 1)));
    v3.push_back(g2 * a);
  }
  long long chh = 9;
  for (i = 0; i < m - 1; i++) chh = chh * 10 + 9;
  long long otv = 1;
  for (i = 0; i < n / m; i++) {
    long long c1, c2;
    c1 = chh / v1[i] + 1;
    c1 = c1 % mo;
    c2 = v2[i] / v1[i];
    c2 += mo;
    c2 = c2 % mo;
    c2 -= (v3[i] - 1) / v1[i];
    c2 += mo;
    c2 = c2 % mo;
    if (v4[i] == 0) {
      c2 = v2[i] / v1[i] + 1;
    }
    otv = ((otv % mo) * (c1 - c2 + mo) % mo) % mo;
  }
  cout << endl << otv;
}
