#include <bits/stdc++.h>
using namespace std;
struct debugger {
  template <typename T>
  debugger &operator,(const T &v) {
    cerr << v << "\t";
    return *this;
  }
} dbg;
template <class T>
void setmax(T &a, T b) {
  if (a < b) a = b;
}
template <class T>
void setmin(T &a, T b) {
  if (b < a) a = b;
}
template <class T>
T Abs(T x) {
  return x > 0 ? x : -x;
}
template <class T>
inline T sqr(T x) {
  return x * x;
}
template <class T>
string toString(T n) {
  ostringstream oss;
  oss << n;
  oss.flush();
  return oss.str();
}
long long toInt(string s) {
  long long r = 0;
  istringstream sin(s);
  sin >> r;
  return r;
}
bool isVowel(char ch) {
  ch = tolower(ch);
  if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u')
    return true;
  return false;
}
bool isUpper(char c) { return c >= 'A' && c <= 'Z'; }
bool isLower(char c) { return c >= 'a' && c <= 'z'; }
long long Pow(long long B, long long P) {
  long long R = 1;
  while (P > 0) {
    if (P % 2 == 1) R = (R * B);
    P /= 2;
    B = (B * B);
  }
  return R;
}
long long BigMod(long long B, long long P, long long M) {
  long long R = 1;
  while (P > 0) {
    if (P % 2 == 1) {
      R = (R * B) % M;
    }
    P /= 2;
    B = (B * B) % M;
  }
  return R;
}
void binprint(long long mask, long long n) {
  long long i;
  string s = "";
  do {
    s += (mask % 2 + '0');
    mask /= 2;
  } while (mask);
  reverse(s.begin(), s.end());
  s = string(max(n - (int)s.size(), 0LL), '0') + s;
  for (i = (int)s.size() - n; i < (int)s.size(); i++) printf("%c", s[i]);
  printf("\n");
}
void ASCII_Chart() {
  long long i, j, k;
  printf("ASCII Chart:(30-129)\n");
  for (i = 30; i < 50; i++) {
    for (j = 0; j < 5; j++) {
      k = i + j * 20;
      printf("%3d---> '%c'   ", k, k);
    }
    printf("\n");
  }
}
const long long Mod = 1000000007;
long long mm[1009][1009][2];
int K;
void Add(long long &re, long long val) {
  re += val;
  re %= Mod;
}
long long bm(long long b, int p) {
  if (!p) return 1;
  long long x = bm(b, p / 2);
  x = (x * x) % Mod;
  if (p & 1) x = (x * b) % Mod;
  return x;
}
long long go(int len, int l, int ch) {
  if (!len) return ch;
  long long &re = mm[len][l][ch];
  if (re > -1) return re;
  re = 0;
  int c, nl;
  for (int i = 0; i < 10; i++) {
    c = 0;
    nl = l;
    if (l <= K && (i == 4 || i == 7)) c = 1;
    if (i == 7 || i == 4) nl = 0;
    Add(re, go(len - 1, min(nl + 1, 1001), ch || c));
  }
  return re;
}
char a[1004], b[1004];
long long cal(char txt[], int p, int l, int k, int ch) {
  if (p == l) return 0;
  long long re = 0, v = txt[p] - 48, nk, c;
  for (int i = 0; i <= v; i++) {
    c = 0;
    if (k <= K && (i == 4 || i == 7)) c = 1;
    nk = k;
    if (i == 4 || i == 7) nk = 0;
    if (i == v)
      Add(re, cal(txt, p + 1, l, min(nk + 1, 1001LL), ch || c));
    else
      Add(re, go(l - p - 1, min(nk + 1, 1001LL), ch || c));
  }
  return re;
}
int check(char txt[], int l) {
  int i, lst = -2 * K;
  for (i = 0; i < l; i++) {
    if (txt[i] - 48 == 4 || txt[i] - 48 == 7) {
      if (i - lst <= K) return 1;
      lst = i;
    }
  }
  return 0;
}
int main() {
  int i, j, test, Case = 1, n, la, lb;
  long long A, B;
  while (scanf("%d%d", &n, &K) == 2) {
    memset(mm, -1, sizeof mm);
    for (i = 0; i < n; i++) {
      scanf("%s%s", a, b);
      la = strlen(a);
      lb = strlen(b);
      A = cal(a, 0, la, K + 1, 0);
      B = cal(b, 0, lb, K + 1, 0);
      A = (check(b, lb) + B - A + Mod) % Mod;
      printf("%I64d\n", A);
    }
  }
  return 0;
}
