Problem: We call a positive integer x a k-beautiful integer if and only if it is possible to split the multiset of its digits in the decimal representation into two subsets such that the difference between the sum of digits in one subset and the sum of digits in the other subset is less than or equal to k. Each digit should belong to exactly one subset after the split.

There are n queries for you. Each query is described with three integers l, r and k, which mean that you are asked how many integers x between l and r (inclusive) are k-beautiful.

Input

The first line contains a single integer n (1 ≤ n ≤ 5·104), indicating the number of queries.

Each of the next n lines describes a query, containing three integers l, r and k (1 ≤ l ≤ r ≤ 1018, 0 ≤ k ≤ 9).

Output

For each query print a single number — the answer to the query.

Examples

Input

10
1 100 0
1 100 1
1 100 2
1 100 3
1 100 4
1 100 5
1 100 6
1 100 7
1 100 8
1 100 9


Output

9
28
44
58
70
80
88
94
98
100


Input

10
1 1000 0
1 1000 1
1 1000 2
1 1000 3
1 1000 4
1 1000 5
1 1000 6
1 1000 7
1 1000 8
1 1000 9


Output

135
380
573
721
830
906
955
983
996
1000

Note

If 1 ≤ x ≤ 9, integer x is k-beautiful if and only if x ≤ k.

If 10 ≤ x ≤ 99, integer x = 10a + b is k-beautiful if and only if |a - b| ≤ k, where a and b are integers between 0 and 9, inclusive.

100 is k-beautiful if and only if k ≥ 1.

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const int oo = 0x3f3f3f3f;
const long long ooo = 9223372036854775807ll;
const int _cnt = 1000 * 1000 + 7;
const int _p = 1000 * 1000 * 1000 + 7;
const int N = 100005;
const double PI = acos(-1.0);
const double eps = 1e-9;
int o(int x) { return x % _p; }
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
void file_put() {
  freopen("filename.in", "r", stdin);
  freopen("filename.out", "w", stdout);
}
bitset<165> B[N];
unordered_map<bitset<165>, int> M;
int T, tot = 0, no[N], k, go[N][10], d[20], top;
long long l, r, s[10][20][N], ans;
int I(const bitset<165> &x) {
  if (M.count(x) == 0) B[M[x] = ++tot] = x;
  return M[x];
}
void init() {
  I(bitset<165>(1));
  for (int i = (1); i <= (tot); ++i)
    for (int j = (0); j <= (9); ++j) {
      bitset<165> t = B[i] << j | B[i] >> j;
      for (int k = (0); k <= (j - 1); ++k)
        if (B[i][k]) t[j - k] = 1;
      go[i][j] = I(t);
    }
  for (int i = (1); i <= (tot); ++i)
    for (int k = (0); k <= (162); ++k) {
      if (B[i][k]) {
        no[i] = k;
        break;
      }
    }
  for (int i = (1); i <= (tot); ++i)
    for (int k = (0); k <= (9); ++k) s[k][0][i] = (k >= no[i]);
  for (int k = (0); k <= (9); ++k)
    for (int i = (1); i <= (19); ++i)
      for (int j = (1); j <= (tot); ++j)
        for (int c = (0); c <= (9); ++c) s[k][i][j] += s[k][i - 1][go[j][c]];
}
long long Query(long long x, int k) {
  for (top = 0; x; x /= 10) d[++top] = x % 10;
  ans = 0;
  for (int i = top, now = 1; i; now = go[now][d[i--]])
    for (int j = (0); j <= (d[i] - 1); ++j) ans += s[k][i - 1][go[now][j]];
  return ans;
}
int main() {
  scanf("%d", &T), init();
  while (T--) {
    scanf("%I64d%I64d%d", &l, &r, &k);
    printf("%I64d\n", Query(r + 1, k) - Query(l, k));
  }
  return 0;
}