#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
class point {
 public:
  int id, val;
};
bool operator<(const point &a, const point &b) {
  if (a.val < b.val) return true;
  return false;
}
int t, k, i, j, p, ans;
int dp[1002][1002][2];
string s1, s2;
string dec(string s) {
  string ans = "";
  int i;
  i = s.length() - 1;
  while (s[i] == '0') {
    i--;
    ans = ans + '9';
  }
  if ((s[i] - 1 > '0') || (i > 0)) ans = char(s[i] - 1) + ans;
  for (i = i - 1; i >= 0; i--) ans = s[i] + ans;
  if (ans.length() == 0) ans = "0";
  return ans;
}
int solve(string s) {
  if (s == "0") return 0;
  int i, j, last = -1;
  int ans = 0;
  int t = 0;
  for (i = 0; i < s.length(); i++) {
    for (j = '0'; j < s[i]; j++)
      if ((j == '4') || (j == '7')) {
        if ((last > -1) && (i - last <= k))
          ans = ((long long)ans + dp[s.length() - 1 - i][i - last][1]) % mod;
        else
          ans = ((long long)ans + dp[s.length() - 1 - i][1][t]) % mod;
      } else if (last == -1)
        ans = ((long long)ans + dp[s.length() - 1 - i][0][t]) % mod;
      else
        ans = ((long long)ans + dp[s.length() - 1 - i][i + 1 - last][t]) % mod;
    if ((s[i] == '4') || (s[i] == '7')) {
      if ((last > -1) && (i - last <= k)) t = 1;
      last = i;
    }
  }
  if (t == 1) ans = (ans + 1) % mod;
  return ans;
}
int main() {
  cin >> t >> k;
  for (i = 0; i <= 1000; i++)
    for (j = 0; j <= 1000 - i; j++)
      for (p = 0; p <= 1; p++) {
        ans = 0;
        if (i == 0) {
          ans = p;
        } else if (p == 1) {
          ans = ((long long)10 * dp[i - 1][j][p]) % mod;
        } else if (j == 0) {
          ans = ((long long)2 * dp[i - 1][1][0]) % mod;
          ans = (ans + (long long)8 * dp[i - 1][0][0]) % mod;
        } else {
          if (j <= k)
            ans = ((long long)2 * dp[i - 1][j][1]) % mod;
          else
            ans = ((long long)2 * dp[i - 1][1][0]) % mod;
          ans = (ans + (long long)8 * dp[i - 1][j + 1][0]) % mod;
        }
        dp[i][j][p] = ans;
      }
  for (i = 1; i <= t; i++) {
    cin >> s1 >> s2;
    s1 = dec(s1);
    cout << ((long long)solve(s2) - solve(s1) + mod) % mod << endl;
  }
  return 0;
}
