#include <bits/stdc++.h>
const int MOD = 1000000007;
using namespace std;
int i, j, k, t, n, d[1005], l;
long long ans1, ans2, ans;
char s[1005];
void read_one() {
  scanf("%s", s);
  n = strlen(s);
  for (i = 0; i < n; i++) d[i + 1] = s[i] - '0';
}
void dec() {
  i = n;
  d[i]--;
  while (d[i] < 0) {
    d[i] = 9;
    i--;
    d[i]--;
  }
}
int good[2][1005], sd[2][1005][1005], dp[2][1005][1005];
inline void z(int& A, int B) {
  A += B;
  if (A >= MOD) A -= MOD;
}
inline int ok(int last, int i) { return (last != 0 && i - last <= k); }
int p10[1005];
int cc[1005][1005];
int rec(int n, int dist, int have = 0) {
  if (have) return p10[n];
  if (n <= 0) return 0;
  int& ret = cc[n][dist];
  if (ret != -1) return ret;
  ret = 0;
  for (int i = 0; i < 10; i++) {
    int have2 = 0;
    int dist2 = dist;
    if (i == 4 || i == 7) {
      if (dist2 != 0 && dist2 <= k)
        have2 = 1;
      else
        dist2 = 1;
    } else {
      if (dist2 != 0) dist2++;
    }
    z(ret, rec(n - 1, dist2, have2));
  }
  return ret;
}
int solve() {
  int last = 0, have = 0, ret = 0, will_have, will_last;
  d[n]++;
  for (i = 1; i <= n; i++) {
    for (j = 0; j < d[i]; j++) {
      will_have = have;
      will_last = last;
      if (j == 4 || j == 7)
        if (ok(last, i)) {
          will_have = 1;
        } else
          will_last = i;
      if (will_have) {
        z(ret, p10[n - i]);
      } else
        z(ret, rec(n - i, (will_last == 0) ? 0 : (i + 1 - will_last)));
    }
    if (d[i] == 4 || d[i] == 7) {
      if (ok(last, i)) {
        have = 1;
      } else
        last = i;
    }
  }
  return ret;
}
int main() {
  scanf("%d%d\n", &t, &k);
  memset(cc, -1, sizeof(cc));
  p10[0] = 1;
  for (i = 1; i <= 1003; i++) p10[i] = p10[i - 1] * 10LL % MOD;
  while (t--) {
    read_one();
    dec();
    ans1 = solve();
    read_one();
    ans2 = solve();
    ans = ans2 - ans1;
    ans %= MOD;
    if (ans < 0) ans += MOD;
    cout << ans << endl;
  }
  return 0;
}
