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