#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5, mod = 1e9 + 7;
int k;
long long dp[2000][3000][2];
int num[2000];
long long dfs(int pos, int dis, bool ok, bool limit) {
  if (pos == -1) return ok;
  if (!limit && dp[pos][dis][ok] != -1) return dp[pos][dis][ok];
  long long ans = 0;
  int up = limit ? num[pos] : 9;
  for (int i = 0; i <= up; i++) {
    int diss = dis + 1;
    bool okk = false;
    if (i == 7 || i == 4) {
      if (dis <= k) okk = true;
      diss = 1;
    }
    ans += dfs(pos - 1, diss, ok | (okk), limit && (i == num[pos]));
    ans %= mod;
  }
  if (!limit) dp[pos][dis][ok] = ans;
  return ans;
}
long long cal(char s[]) {
  int len = strlen(s);
  for (int i = 0; i < len; i++) {
    num[len - i - 1] = s[i] - '0';
  }
  return dfs(len - 1, k + 5, false, true);
}
char l[1200], r[1200];
int main() {
  int t;
  memset(dp, -1, sizeof(dp));
  cin >> t >> k;
  while (t--) {
    cin >> l >> r;
    int len = strlen(l);
    int p = len - 1;
    while (l[p] == '0') l[p--] = '9';
    l[p]--;
    cout << (cal(r) - cal(l) + mod) % mod << endl;
  }
}
