#include <bits/stdc++.h>
using namespace std;
long long int dp[1005ll][1005ll][2], k, mod = 1000000007ll;
long long int recur(long long int pos, long long int dis, long long int ok) {
  dis = min(k, dis);
  long long int &res = dp[pos][dis][ok];
  if (res != -1) return res;
  if (pos == 0) return res = ok;
  return res = (recur(pos - 1, dis + 1, ok) * 8 +
                recur(pos - 1, 0, ok | (dis < k)) * 2) %
               mod;
}
long long int cal(string str, bool include) {
  long long int dis = (1ll << (long long int)(60)), ok = 0, res = 0;
  for (long long int i = 0; i < ((long long int)(((long long int)str.size())));
       i++) {
    for (long long int j = 0; j < str[i] - '0'; j++) {
      if (j != 4 && j != 7)
        res += recur(((long long int)str.size()) - 1 - i, dis + 1, ok);
      else
        res += recur(((long long int)str.size()) - 1 - i, 0, ok | (dis < k));
    }
    if (str[i] == '4' || str[i] == '7') {
      ok |= (dis < k);
      dis = 0;
    } else
      dis++;
  }
  if (include) res += ok;
  return res % mod;
}
int main() {
  memset(dp, -1, sizeof(dp));
  long long int n;
  scanf("%I64d%I64d", &n, &k);
  for (long long int i = 0; i < ((long long int)(n)); i++) {
    char low[1005ll], high[1005ll];
    scanf("%s%s", low, high);
    cout << (cal(high, true) - cal(low, false) + mod) % mod << endl;
  }
}
