#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
string a, b;
char c[1005];
long long dp[1005][1005][2];
int k;
long long dfs(int pos, int ju, bool lim, int luc) {
  if (pos == -1) return luc;
  if (!lim && dp[pos][ju][luc] != -1) return dp[pos][ju][luc];
  long long num = lim ? c[pos] - '0' : 9;
  long long i, ret = 0;
  for (int i = 0; i <= num; i++) {
    if (i == 4 || i == 7) {
      if (ju == -1) {
        ret += dfs(pos - 1, pos, lim && (i == num), luc);
      } else {
        ret += dfs(pos - 1, pos, lim && (i == num), luc | (ju - pos <= k));
      }
    } else {
      ret += dfs(pos - 1, ju, lim && (i == num), luc);
    }
    ret %= mod;
  }
  if (!lim) dp[pos][ju][luc] = ret;
  return ret;
}
long long solve(string s) {
  for (int i = 0; i < s.length(); i++) {
    c[s.length() - i - 1] = s[i];
  }
  return dfs(s.length() - 1, -1, 1, 0);
}
int main() {
  int t;
  scanf("%d%d", &t, &k);
  memset(dp, -1, sizeof(dp));
  while (t--) {
    cin >> a >> b;
    int now = a.length() - 1;
    while (a[now] == '0') {
      a[now] = '9';
      now--;
    }
    a[now] = (a[now] - 1);
    printf("%lld\n", (solve(b) - solve(a) + mod) % mod);
  }
  return 0;
}
