#include <bits/stdc++.h>
using namespace std;
int t, k;
long long pw8[1010];
long long f[1010][2];
char L[1010], R[1010];
void pre_cal() {
  pw8[0] = 1;
  for (int i = 1; i <= 1000; i++) pw8[i] = pw8[i - 1] * 8 % 1000000007;
  memset(f, 0, sizeof(f));
  f[1][1] = 8;
  f[1][0] = 2;
  f[0][0] = 1;
  for (int len = 2; len <= 1000; len++) {
    for (int i = min(k + 1, len); i <= len; i++)
      f[len][0] = (f[len][0] + 2 * (f[len - i][0] * pw8[i - 1])) % 1000000007;
    f[len][1] = (8 * (f[len - 1][1] + f[len - 1][0])) % 1000000007;
  }
}
long long cal(char *s) {
  int len = strlen(s);
  long long total = 0, anti = 0;
  for (int i = 0; s[i]; i++) total = (total * 10 + s[i] - '0') % 1000000007;
  int last = -0x3fffffff;
  for (int i = 0; i < len; i++) {
    char end = (i == len - 1 ? s[i] : s[i] - 1);
    for (char j = '0'; j <= end; j++) {
      int near = last;
      if (j == '4' || j == '7') {
        near = i;
        if (i - last <= k) continue;
      }
      int pos = near + k + 1;
      if (pos > len) pos = len;
      if (pos <= i) {
        anti = (anti + (f[len - i - 1][0] + f[len - i - 1][1])) % 1000000007;
      } else {
        anti = (anti + pw8[pos - i - 1] * (f[len - pos][0] + f[len - pos][1])) %
               1000000007;
      }
    }
    if (s[i] == '4' || s[i] == '7') {
      if (i - last <= k) break;
      last = i;
    }
  }
  return ((total - anti) % 1000000007 + 1000000007) % 1000000007;
}
bool check(char *s) {
  int last = -0x3fffffff;
  for (int i = 0; s[i]; i++) {
    if (s[i] == '4' || s[i] == '7') {
      if (i - last <= k) return true;
      last = i;
    }
  }
  return false;
}
int main() {
  while (scanf("%d%d", &t, &k) != EOF) {
    pre_cal();
    while (t--) {
      scanf("%s%s", L, R);
      long long d1 = cal(L);
      long long d2 = cal(R);
      if (check(L)) d2++;
      cout << ((d2 - d1) % 1000000007 + 1000000007) % 1000000007 << endl;
    }
  }
  return 0;
}
