#include <bits/stdc++.h>
using namespace std;
const int a1[2] = {8, 2};
int i, j, k, n, m, K, x;
int f[1010][1010], h[1010][1010], w[1010];
char p[1010];
inline void M(int &x, int y) { x = (x + y) % 1000000007; }
inline void pre() {
  f[0][0] = 1;
  for (i = 0; i <= 1010 - 5; i++)
    for (j = 0; j <= K + 1; j++)
      if (x = f[i][j]) {
        for (k = 0; k <= 9; k++) {
          int A = k == 4 || k == 7;
          if (j > K)
            M(f[i + 1][K + 1], x);
          else if (!j) {
            if (!A)
              M(f[i + 1][0], x);
            else
              M(f[i + 1][1], x);
          } else {
            if (A)
              M(f[i + 1][K + 1], x);
            else if (j < K)
              M(f[i + 1][j + 1], x);
            else
              M(f[i + 1][0], x);
          }
        }
      }
  for (i = 0; i <= 1010 - 5; i++) {
    h[i][0] = f[i][0];
    for (j = 1; j <= K + 1; j++) h[i][j] = (h[i][j - 1] + f[i][j]) % 1000000007;
  }
  w[0] = 1;
  for (i = 1; i <= 1010 - 5; i++) w[i] = 10ll * w[i - 1] % 1000000007;
}
inline int cal(int ty) {
  scanf("%s", p + 1);
  int n = strlen(p + 1), i, j, an = f[n - 1][K + 1], dis = K + 1;
  for (i = n; i; i--) {
    int l = i == n ? 1 : 0,
        r = (i == 1 ? p[n - i + 1] - ty : p[n - i + 1] - 1) - '0';
    for (j = l; j <= r; j++) {
      int A = j == 4 || j == 7;
      if (A) {
        if (dis == K + 1)
          M(an, (h[i - 1][K + 1] - h[i - 1][0]) % 1000000007);
        else
          M(an, w[i - 1]);
      } else {
        if (!dis)
          M(an, w[i - 1]);
        else {
          M(an, f[i - 1][K + 1]);
          if (dis <= K) M(an, (h[i - 1][dis - 1] - h[i - 1][0]) % 1000000007);
        }
      }
    }
    int w = p[n - i + 1] - '0';
    if (w == 4 || w == 7) {
      if (dis != K + 1)
        dis = 0;
      else
        dis = K;
    } else {
      if (dis && dis <= K) {
        if (dis == 1)
          dis = K + 1;
        else
          dis--;
      }
    }
  }
  return an;
}
int main() {
  scanf("%d%d", &n, &K);
  pre();
  for (i = 1; i <= n; i++) {
    int A = -cal(1);
    A = (A + cal(0)) % 1000000007;
    printf("%d\n", (A + 1000000007) % 1000000007);
  }
  return 0;
}
