#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000;
const int MOD = 1e9 + 7;
int memo[MAXN + 1][MAXN + 1][2];
int dig[MAXN + 1];
int n, k;
void fast_io() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
}
int solve(int pos, int l, bool ok, bool t) {
  if (!pos) return ok;
  if (!t and memo[pos][l][ok] != -1) return memo[pos][l][ok];
  int lim = (t ? dig[pos] : 9);
  int res = 0;
  for (int i = 0; i <= lim; i++) {
    if (!(i ^ 4) | !(i ^ 7))
      res +=
          solve(pos - 1, pos, ((l > 0) & (l - pos <= k)) | ok, !(i ^ lim) & t);
    else
      res += solve(pos - 1, l, ok, !(i ^ lim) & t);
    if (res >= MOD) res -= MOD;
  }
  if (!t) memo[pos][l][ok] = res;
  return res;
}
bool brute(string &S) {
  vector<int> pos;
  for (int i = 0; i < S.length(); i++)
    if (S[i] == '4' | S[i] == '7') pos.push_back(i);
  for (int i = 1; i < pos.size(); i++)
    if (pos[i] - pos[i - 1] <= k) return true;
  return false;
}
int count(string &S) {
  n = S.length();
  for (int i = 1; i <= n; i++) dig[i] = S[i - 1] - '0';
  reverse(dig + 1, dig + n + 1);
  return solve(n, 0, 0, 1);
}
int main() {
  fast_io();
  memset(memo, -1, sizeof(memo));
  int tc, ans;
  string l, r;
  cin >> tc >> k;
  while (tc--) {
    cin >> l >> r;
    ans = count(r) - count(l) + brute(l);
    if (ans < 0) ans += MOD;
    cout << ans << '\n';
  }
  return 0;
}
