#include <bits/stdc++.h>
using namespace std;
long tests, k, dp[1050][1050][3], nend, nwas, luck[20000];
long pw[20000];
string st1, st2;
void add(long &a, long &b) {
  a += b;
  if (a >= 1000000007) a -= 1000000007;
}
bool check(string st) {
  long l = -100000;
  for (int i = 0; i < st.size(); i++) {
    if (st[i] == '4' || st[i] == '7') {
      if (i - k <= l) return 1;
      l = i;
    }
  }
  return 0;
}
long solve(string st) {
  long ans = 0;
  if (check(st)) ++ans;
  long lnice = -1;
  long isgood = 0;
  for (int i = 0; i < st.size(); i++) {
    for (int j = 0; j + 48 < st[i]; j++) {
      long tg = isgood;
      long tl = lnice;
      if (j == 4 || j == 7) {
        if (lnice >= 0 && lnice + k >= i) tg = 1;
        tl = i;
      }
      if (i + 1 == st.size()) {
        long one = 1;
        if (tg) add(ans, one);
      } else if (tg == 1) {
        add(ans, pw[st.size() - i - 1]);
      } else if (tl == -1 || tl + k <= i) {
        add(ans, luck[st.size() - i - 1]);
      } else {
        add(ans, luck[st.size() - i - 1]);
        long aps = k - (i - tl);
        if (aps >= (st.size() - i)) aps = st.size() - i - 1;
        add(ans, dp[st.size() - i - 1][st.size() - i - aps][0]);
      }
    }
    if (st[i] == '4' || st[i] == '7')
      if (lnice >= 0 && lnice + k >= i) isgood = 1;
    if (st[i] == '4' || st[i] == '7') lnice = i;
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> tests;
  cin >> k;
  dp[0][0][0] = 1;
  for (int i = 0; i <= 1000; i++)
    for (int j = 0; j <= i; j++)
      for (int was = 0; was <= 1; was++)
        for (int ad = 0; ad <= 9; ad++) {
          nend = j;
          nwas = was;
          if (ad == 4 || ad == 7) nend = i + 1;
          if (j > 0 && nend == i + 1 && nend - j <= k) nwas = 1;
          add(dp[i + 1][nend][nwas], dp[i][j][was]);
        }
  for (int i = 0; i <= 1000; i++)
    for (int j = 0; j <= i; j++) add(luck[i], dp[i][j][1]);
  for (int i = 0; i <= 1000; i++)
    for (int j = i; j > 0; j--) add(dp[i][j][0], dp[i][j + 1][0]);
  pw[0] = 1;
  for (int i = 1; i <= 1000; i++) pw[i] = (pw[i - 1] * 1ll * 10) % 1000000007;
  for (; tests; --tests) {
    cin >> st1 >> st2;
    long res = solve(st2);
    res -= solve(st1);
    if (check(st1)) ++res;
    if (res >= 1000000007) res -= 1000000007;
    if (res < 0) res += 1000000007;
    cout << res << endl;
  }
  cin.get();
  cin.get();
  return 0;
}
