#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int N = 1005;
int digit[N];
long long dp[N][N][2];
char l[N], r[N];
int k;
int dfs(int len, int p, bool flag, bool limit) {
  if (len == 0) return flag;
  if (limit == 0 && dp[len][p][flag] != -1) return dp[len][p][flag];
  int up = limit ? digit[len] : 9;
  int res = 0;
  for (int i = 0; i < up + 1; i++) {
    if (i != 4 && i != 7)
      res = (res + dfs(len - 1, max(0, p - 1), flag, limit && i == up)) % mod;
    else
      res = (res + dfs(len - 1, 1 * k, flag || p, limit && i == up)) % mod;
  }
  if (!limit) dp[len][p][flag] = res;
  return res;
}
inline void solve() {
  int t;
  memset(dp, -1, sizeof dp);
  scanf("%d%d", &t, &k);
  while (t--) {
    scanf("%s%s", l, r);
    int len = strlen(r);
    for (int i = len; i >= 0; i--) digit[i] = r[len - i] - '0';
    int ans = dfs(len, 0, 0, 1);
    len = strlen(l);
    for (int i = len; i >= 0; i--) digit[i] = l[len - i] - '0';
    digit[1]--;
    for (int i = 1; digit[i] < 0; i++) {
      digit[i] += 10;
      digit[i + 1]--;
    }
    if (digit[len] == 0) len--;
    ans = (ans - dfs(len, 0, 0, 1) + mod) % mod;
    printf("%d\n", ans);
  }
}
int main() {
  std::ios::sync_with_stdio(false);
  solve();
}
