#include <bits/stdc++.h>
const int mod = 1e9 + 7;
using namespace std;
int t, k, c[1005], dp[1005][1005][2];
char a[1005], b[1005];
long long dfs(int step, int d, int q, int flag) {
  if (!step) return q;
  if (!flag && dp[step][d][q] != -1) return dp[step][d][q];
  long long res = 0;
  int up = flag ? c[step] : 9;
  for (int i = 0; i <= up; i++) {
    if (i != 4 && i != 7)
      res = (res + dfs(step - 1, max(d - 1, 0), q, flag && i == up)) % mod;
    else
      res = (res + dfs(step - 1, k, q || d, flag && i == up)) % mod;
  }
  if (!flag) dp[step][d][q] = res;
  return res;
}
long long solve(char x[]) {
  int len = strlen(x + 1);
  for (int i = len; i >= 1; i--) c[len - i + 1] = x[i] - '0';
  return dfs(len, 0, 0, 1);
}
int check() {
  int len = strlen(a + 1);
  int last = -0x3f3f3f3f;
  for (int i = 1; i <= len; i++) {
    if (a[i] == '4' || a[i] == '7') {
      if (i - last <= k) return 1;
      last = i;
    }
  }
  return 0;
}
int main() {
  scanf("%d%d", &t, &k);
  memset(dp, -1, sizeof(dp));
  while (t--) {
    scanf("%s%s", a + 1, b + 1);
    printf("%lld\n", (solve(b) - solve(a) + check() + mod) % mod);
  }
}
