#include <bits/stdc++.h>
using namespace std;
long long Set(long long n, long long pos) { return n | (1LL << pos); }
bool Check(long long n, long long pos) { return (bool)(n & (1LL << pos)); }
long long yo = 1000;
char a[1010], b[1010];
long long dp[1010][2][2][1010][2];
long long k;
long long solve(long long pos, bool isSmall, bool isLarge, long long prev,
                long long ok) {
  if (pos > yo) {
    return ok;
  }
  long long &ret = dp[pos][isSmall][isLarge][prev][ok];
  if (ret != -1 && isSmall && isLarge) return ret;
  long long lo = 0, hi = 9;
  if (!isSmall) hi = b[pos] - '0';
  if (!isLarge) lo = a[pos] - '0';
  ret = 0;
  for (long long i = lo; i <= hi; i++) {
    ret = (ret + solve(pos + 1, (i < b[pos] - '0') ? 1 : isSmall,
                       (i > a[pos] - '0') ? 1 : isLarge,
                       (i == 4 || i == 7) ? pos : prev,
                       ((i == 4 || i == 7) && pos - prev <= k && prev != yo + 1)
                           ? 1
                           : ok)) %
          1000000007;
  }
  return ret;
}
int main() {
  long long cs, ts, i, j, x, y, z, q, m, n, v;
  memset(dp, -1, sizeof(dp));
  scanf("%lld", &ts);
  scanf("%lld", &k);
  for (cs = 1; cs <= ts; cs++) {
    scanf("%s", a);
    scanf("%s", b);
    long long lena = strlen(a);
    for (i = yo; i >= 0; i--) {
      if (lena - 1 - (yo - i) >= 0)
        a[i] = a[lena - 1 - (yo - i)];
      else
        a[i] = '0';
    }
    long long lenb = strlen(b);
    for (i = yo; i >= 0; i--) {
      if (lenb - 1 - (yo - i) >= 0)
        b[i] = b[lenb - 1 - (yo - i)];
      else
        b[i] = '0';
    }
    printf("%lld\n", solve(0, 0, 0, yo + 1, 0));
  }
  return 0;
}
