#include <bits/stdc++.h>
using namespace std;
long long dp[1001][1001][2][2][2][2];
int ln = 1000, k;
string arr, brr;
long long fun(int pos, int prev, int choto, int boro, int suru, int status) {
  if (pos < 0) {
    return status;
  }
  long long &ret = dp[pos][prev][choto][boro][suru][status];
  if (ret != -1 && choto && boro) return ret;
  int lo = 0, hi = 9;
  if (choto == 0) hi = brr[pos] - '0';
  if (boro == 0) lo = arr[pos] - '0';
  ret = 0;
  for (int i = lo; i <= hi; i++) {
    int n_prev = prev;
    int n_status = status;
    int n_suru = suru;
    if (i == 4 || i == 7) {
      if (n_suru == 1) {
        if (abs(pos - n_prev) <= k) n_status |= 1;
      }
      n_suru |= 1;
      n_prev = pos;
    }
    ret += fun(pos - 1, n_prev, choto | (i < hi), boro | (i > lo), n_suru,
               n_status);
    ret %= 1000000007;
  }
  return ret;
}
int main() {
  int t;
  scanf("%d %d", &t, &k);
  memset(dp, -1, sizeof(dp));
  while (t--) {
    cin >> arr >> brr;
    string addd = arr;
    string add = "";
    int sz = max(arr.size(), brr.size());
    int dif = sz - arr.size();
    while (dif--) add += '0';
    arr = add + arr;
    add = "";
    dif = sz - brr.size();
    while (dif--) add += '0';
    brr = add + brr;
    reverse(arr.begin(), arr.end());
    reverse(brr.begin(), brr.end());
    long long ans = fun(sz - 1, 0, 0, 0, 0, 0);
    printf("%lld\n", ans);
  }
  return 0;
}
