#include <bits/stdc++.h>
using namespace std;
const int MAX_STRING_LENGTH = 4e3;
struct _io {
  char buff[MAX_STRING_LENGTH];
  _io &operator>>(int &x) {
    scanf("%d", &x);
    return *this;
  }
  _io &operator>>(long long &x) {
    scanf("%lld", &x);
    return *this;
  }
  _io &operator>>(float &x) {
    scanf("%f", &x);
    return *this;
  }
  _io &operator>>(double &x) {
    scanf("%lf", &x);
    return *this;
  }
  _io &operator>>(long double &x) {
    scanf("%Lf", &x);
    return *this;
  }
  _io &operator>>(char &c) {
    do {
      scanf("%c", &c);
    } while (c == ' ' || c == '\n');
    return *this;
  }
  _io &operator>>(char *s) {
    scanf("%s", s);
    return *this;
  }
  _io &operator>>(string &s) {
    scanf("%s", buff);
    s = string(buff, strlen(buff));
    return *this;
  }
  _io &operator<<(const int x) {
    printf("%d", x);
    return *this;
  }
  _io &operator<<(const long long x) {
    printf("%lld", x);
    return *this;
  }
  _io &operator<<(const float x) {
    printf("%f", x);
    return *this;
  }
  _io &operator<<(const double &x) {
    printf("%lf", x);
    return *this;
  }
  _io &operator<<(const long double &x) {
    printf("%Lf", x);
    return *this;
  }
  _io operator<<(const char &c) {
    printf("%c", c);
    return *this;
  }
  _io &operator<<(const string &s) {
    printf("%s", s.c_str());
    return *this;
  }
  _io &operator<<(const char *s) {
    printf("%s", s);
    return *this;
  }
} io;
int i, j, k;
long long n, bl, minpow10, maxpow10, cfac, nbl;
const int grtn = 1e6 + 10;
const long long mod = 1e9 + 7;
long long fac[grtn], dig[grtn];
long long mul[grtn];
long long modul(long long x) { return ((x % mod) + mod) % mod; }
int main() {
  io >> n >> bl;
  nbl = n / bl;
  for (i = 0; i < nbl; ++i) io >> fac[i];
  for (i = 0; i < nbl; ++i) io >> dig[i];
  minpow10 = 1;
  for (int i = 1; i < bl; ++i) minpow10 *= 10;
  maxpow10 = minpow10 * 10;
  for (i = 0; i < nbl; ++i) {
    if (dig[i] != 0) mul[i] = 1;
    mul[i] = modul(mul[i] + (maxpow10 - 1) / fac[i] -
                   (((dig[i] + 1) * minpow10 - 1) / fac[i] -
                    (max(dig[i] * minpow10 - 1, 0ll)) / fac[i]));
  }
  for (i = 1; i < nbl; ++i) {
    mul[i] = modul(mul[i] * mul[i - 1]);
  }
  io << mul[nbl - 1];
  return 0;
}
