#include <bits/stdc++.h>
using namespace std;
template <class A, class B>
A convert(B x) {
  stringstream s;
  s << x;
  A r;
  s >> r;
  return r;
}
int len, k;
int dp[1010][1010];
int calc[1010];
const int mod = 1000000007;
string S;
int Add(int a, int b) { return a + b >= mod ? a + b - mod : a + b; }
int Sub(int a, int b) { return a - b < 0 ? a - b + mod : a - b; }
int Mul(int a, int b) { return ((long long)a * (long long)b) % mod; }
int Rec(int p, int last) {
  if (p == 0) return 0;
  if (last > k) last = k + 1;
  int& res = dp[p][last];
  if (res != -1) return res;
  if (last <= k)
    res = Mul(calc[p - 1], 2);
  else
    res = Mul(Rec(p - 1, 1), 2);
  res = Add(res, Mul(Rec(p - 1, last + 1), 8));
  return res;
}
int Check(string s) {
  int last = -k - 1;
  for (int i = (0), _b(((int)(s).size())); i < _b; ++i) {
    if (s[i] == '4' || s[i] == '7') {
      if (i - last <= k) return 1;
      last = i;
    }
  }
  return 0;
}
int ToInt(int pos) {
  int res = 0;
  for (int i = (pos), _b(((int)(S).size())); i < _b; ++i) {
    res = Mul(res, 10);
    res = Add(res, S[i] - '0');
  }
  return res;
}
int Calc(int pos, int last) {
  if (pos == ((int)(S).size())) return 0;
  int res = 0;
  if (!pos) res = Rec(((int)(S).size()) - 1, k + 1);
  for (int i = (pos == 0), _b(S[pos] - '0'); i < _b; ++i)
    if (i == 4 || i == 7)
      if (pos - last <= k)
        res = Add(res, calc[((int)(S).size()) - pos - 1]);
      else
        res = Add(res, Rec(((int)(S).size()) - pos - 1, 1));
    else
      res = Add(res, Rec(((int)(S).size()) - pos - 1, pos - last + 1));
  if (S[pos] == '4' || S[pos] == '7') {
    if (pos - last <= k)
      res = Add(res, ToInt(pos + 1) + 1);
    else
      res = Add(res, Calc(pos + 1, pos));
  } else
    res = Add(res, Calc(pos + 1, last));
  return res;
}
int Calc(string N) {
  S = N;
  return Calc(0, -k - 1);
}
int Brut(int L, int R) {
  int res = 0;
  for (int i = (L), _b(R + 1); i < _b; ++i)
    res += Check(convert<string, int>(i));
  return res;
}
int main() {
  calc[0] = 1;
  for (int i = (1), _b(1010); i < _b; ++i) calc[i] = Mul(calc[i - 1], 10);
  int tc;
  scanf("%d %d", &tc, &k);
  string l, r;
  memset(dp, -1, sizeof(dp));
  while (tc-- > 0) {
    cin >> l >> r;
    cout << Sub(Calc(r), Sub(Calc(l), Check(l))) << endl;
  }
  return 0;
}
