#include <bits/stdc++.h>
using namespace std;
const int MX = 1e5 + 5;
const int mod = 1e9 + 7;
long long F[100];
long long A[MX], B[MX];
long long solve(long long L, long long R, long long x) {
  long long ret = R / x - L / x;
  if (L % x == 0) ret++;
  return ret;
}
long long get(int k, long long a, int b) {
  if (b == 0) return solve(F[k - 1], F[k] - 1, a);
  if (b == 9) return solve(0, F[k - 1] * 9 - 1, a);
  return solve(0, F[k - 1] * b - 1, a) + solve(F[k - 1] * (b + 1), F[k] - 1, a);
}
int main() {
  F[0] = 1;
  for (int i = 1; i <= 9; i++) F[i] = F[i - 1] * 10;
  int n, k;
  while (~scanf("%d%d", &n, &k)) {
    int m = n / k;
    for (int i = 1; i <= m; i++) {
      scanf("%I64d", &A[i]);
    }
    for (int i = 1; i <= m; i++) {
      scanf("%I64d", &B[i]);
    }
    long long ans = 1;
    for (int i = 1; i <= m; i++) {
      ans *= get(k, A[i], B[i]);
      ans %= mod;
    }
    printf("%I64d\n", ans);
  }
  return 0;
}
