#include <bits/stdc++.h>
constexpr int P = 1000000007;
int k, len;
int bit[1010];
int dp[1010][1010][2];
char s[1010];
constexpr int max(const int &x, const int &y) { return (x < y) ? y : x; }
constexpr int fix(const int &x) { return x + ((x >> 31) & P); }
int dfs(const int &pos, const int &d, const bool &sta, const bool &up) {
  if (!pos) return sta;
  int &ans = dp[pos][d][sta];
  if (!up && ~ans) return ans;
  ans = 0;
  const int lim = (up ? bit[pos] : 9);
  for (int i = 0; i <= lim; ++i) {
    if (i == 4 || i == 7) {
      ans = fix(ans + dfs(pos - 1, k, sta || d, up && i == lim) - P);
    } else {
      ans = fix(ans + dfs(pos - 1, max(d - 1, 0), sta, up && i == lim) - P);
    }
  }
  if (up) {
    const int res = ans;
    ans = -1;
    return res;
  }
  return ans;
}
bool chk() {
  int lst = 0x7fffffff;
  for (int i = len; i >= 1; --i) {
    if (bit[i] == 4 || bit[i] == 7) {
      if (lst - i <= k) return true;
      lst = i;
    }
  }
  return false;
}
int main() {
  memset(dp, -1, sizeof dp);
  int T;
  scanf("%d%d", &T, &k);
  while (T--) {
    scanf("%s", s + 1);
    len = strlen(s + 1);
    for (int i = 1; i <= len; ++i) bit[len - i + 1] = s[i] ^ 48;
    int ans = dfs(len, 0, false, true) - chk();
    scanf("%s", s + 1);
    len = strlen(s + 1);
    for (int i = 1; i <= len; ++i) bit[len - i + 1] = s[i] ^ 48;
    ans = fix(dfs(len, 0, false, true) - ans);
    printf("%d\n", ans);
  }
  return 0;
}
