#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int a[100005], b[100005];
int dp[10][10][100005];
int pow10(int k) {
  int ret = 1;
  while (k--) ret *= 10;
  return ret;
}
int main() {
  int n, K, m, ans = 1;
  scanf("%d%d", &n, &K);
  m = n / K;
  for (int i = 0; i < m; i++) scanf("%d", &a[i]);
  for (int i = 0; i < m; i++) scanf("%d", &b[i]);
  for (int i = 1; i <= 9; i++) {
    for (int j = 1; j <= K; j++) {
      for (int k = 0; k < m; k++)
        dp[i][j][k] = (((i + 1) * pow10(j - 1) - 1) / a[k] -
                       ((i)*pow10(j - 1) - 1) / a[k]) %
                      mod;
    }
  }
  for (int i = 0; i < m; i++) dp[0][0][i] = 1;
  for (int i = 1; i <= K; i++) {
    for (int j = 0; j < m; j++) {
      for (int k = 0; k <= 9; k++)
        dp[0][i][j] = dp[0][i][j] + dp[k][i - 1][j] % mod;
    }
  }
  for (int i = 0; i < m; i++) {
    int t = 0;
    for (int j = 0; j <= 9; j++) {
      if (j == b[i]) continue;
      t = t + dp[j][K][i] % mod;
    }
    ans = 1LL * ans * t % mod;
  }
  printf("%d\n", ans);
}
