#include <bits/stdc++.h>
using namespace std;
int T, k;
int num[1005];
char l[1005], r[1005];
long long dp[1005][1005][2];
long long dfs(int pos, int d, bool flag, bool lim) {
  if (!pos) return flag;
  if (!lim && ~dp[pos][d][flag]) return dp[pos][d][flag];
  int up = lim ? num[pos] : 9;
  long long ans = 0;
  for (int i = 0; i <= up; i++) {
    if (i != 4 && i != 7)
      ans = (ans + dfs(pos - 1, max(d - 1, 0), flag, lim && (i == up))) %
            1000000007;
    else
      ans = (ans + dfs(pos - 1, k, flag || d, lim && (i == up))) % 1000000007;
  }
  if (!lim) dp[pos][d][flag] = ans;
  return ans;
}
long long calc(char *x) {
  int len = strlen(x);
  for (int i = len - 1; i >= 0; i--) num[len - i] = x[i] - '0';
  return dfs(len, 0, 0, 1);
}
bool check() {
  int len = strlen(l), last = 0x3f3f3f3f;
  for (int i = len - 1; ~i; i--) {
    int j = l[i] - '0';
    if (j == 4 || j == 7) {
      if (last - i <= k)
        return 1;
      else
        last = i;
    }
  }
  return 0;
}
int main() {
  memset(dp, -1, sizeof(dp));
  scanf("%d %d", &T, &k);
  while (T--) {
    scanf("%s %s", l, r);
    printf("%lld\n", (calc(r) - calc(l) + check() + 1000000007) % 1000000007);
  }
  return 0;
}
