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;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
const int MAXK = 9;
const int MAXLEN = 19;
const int MAXS = 9 * MAXLEN / 2;
const int XLEN = 5;
int xoff[10];
long long xmask[10];
vector<long long> opt[MAXK + 1][MAXLEN + 1];
vector<long long> ways[MAXK + 1][MAXLEN + 1][10];
long long wayspar[2][MAXLEN + 1];
bitset<MAXS + 1> can[10];
void dfscan(int d, int cnt, int sum, long long x) {
  if (d > 9) {
    int mx = sum / 2;
    while (!can[d - 1].test(mx)) --mx;
    int k = sum - 2 * mx;
    assert(k <= MAXK);
    if (k >= 2) opt[k][0].push_back(x);
  } else {
    can[d] = can[d - 1];
    while (true) {
      dfscan(d + 1, cnt, sum, x);
      if (cnt >= MAXLEN) break;
      ++cnt;
      sum += d;
      x += 1LL << xoff[d];
      can[d] |= can[d] << d;
    }
  }
}
void precalc() {
  wayspar[0][0] = 1;
  for (int i = (0); i < (MAXLEN); ++i)
    wayspar[0][i + 1] = wayspar[0][i] * 5 + wayspar[1][i] * 5,
                   wayspar[1][i + 1] = wayspar[0][i] * 5 + wayspar[1][i] * 5;
  xoff[1] = 0;
  for (int i = (2); i <= (9); ++i) xoff[i] = xoff[i - 1] + XLEN;
  for (int i = (1); i <= (9); ++i)
    xmask[i] = ((long long)((1 << XLEN) - 1)) << xoff[i];
  can[0].set(0);
  dfscan(1, 0, 0, 0);
  for (int k = (2); k <= (MAXK); ++k) {
    sort(opt[k][0].begin(), opt[k][0].end());
    opt[k][0].erase(unique(opt[k][0].begin(), opt[k][0].end()),
                    opt[k][0].end());
    for (int d = (0); d < (10); ++d)
      ways[k][0][d] = vector<long long>(((int)(opt[k][0]).size()), 1);
    for (int i = (0); i < (MAXLEN); ++i) {
      for (int x = (0); x < (((int)(opt[k][i]).size())); ++x) {
        int sum = 0;
        for (int d = (1); d <= (9); ++d)
          if ((opt[k][i][x] & xmask[d]) != 0)
            opt[k][i + 1].push_back(opt[k][i][x] - (1LL << xoff[d])),
                sum += (opt[k][i][x] & xmask[d]) >> xoff[d];
        if (sum < MAXLEN) opt[k][i + 1].push_back(opt[k][i][x]);
      }
      sort(opt[k][i + 1].begin(), opt[k][i + 1].end());
      opt[k][i + 1].erase(unique(opt[k][i + 1].begin(), opt[k][i + 1].end()),
                          opt[k][i + 1].end());
      for (int d = (0); d < (10); ++d)
        ways[k][i + 1][d] = vector<long long>(((int)(opt[k][i + 1]).size()), 0);
      for (int x = (0); x < (((int)(opt[k][i]).size())); ++x) {
        int sum = 0;
        for (int d = (1); d <= (9); ++d)
          if ((opt[k][i][x] & xmask[d]) != 0) {
            int nx = lower_bound(opt[k][i + 1].begin(), opt[k][i + 1].end(),
                                 opt[k][i][x] - (1LL << xoff[d])) -
                     opt[k][i + 1].begin();
            assert(0 <= nx && nx < ((int)(opt[k][i + 1]).size()) &&
                   opt[k][i + 1][nx] == opt[k][i][x] - (1LL << xoff[d]));
            ways[k][i + 1][d][nx] += ways[k][i][9][x];
            sum += (opt[k][i][x] & xmask[d]) >> xoff[d];
          }
        if (sum < MAXLEN) {
          int nx = lower_bound(opt[k][i + 1].begin(), opt[k][i + 1].end(),
                               opt[k][i][x]) -
                   opt[k][i + 1].begin();
          assert(0 <= nx && nx < ((int)(opt[k][i + 1]).size()) &&
                 opt[k][i + 1][nx] == opt[k][i][x]);
          ways[k][i + 1][0][nx] += ways[k][i][9][x];
        }
      }
      for (int d = (1); d <= (9); ++d)
        for (int x = (0); x < (((int)(opt[k][i + 1]).size())); ++x)
          ways[k][i + 1][d][x] += ways[k][i + 1][d - 1][x];
    }
  }
}
char s[MAXLEN + 1];
long long calc(long long lim, int k) {
  sprintf(s, "%lld", lim);
  int slen = strlen(s);
  long long ret = 0, x = 0;
  for (int i = (0); i < (slen); ++i) {
    int d = s[i] - '0';
    if (d == 0) continue;
    int idx = lower_bound(opt[k][slen - i].begin(), opt[k][slen - i].end(), x) -
              opt[k][slen - i].begin();
    if (idx != ((int)(opt[k][slen - i]).size()) && opt[k][slen - i][idx] == x) {
      ret += ways[k][slen - i][d - 1][idx];
    }
    x += 1LL << xoff[d];
  }
  return ret;
}
long long calcodd(long long lim) {
  sprintf(s, "%lld", lim);
  int slen = strlen(s);
  long long ret = 0;
  int par = 0;
  for (int i = (0); i < (slen); ++i) {
    int d = s[i] - '0';
    if (d == 0) continue;
    int oddhere = d / 2, evnhere = (d + 1) / 2;
    ret += wayspar[par][slen - i - 1] * oddhere +
           wayspar[1 - par][slen - i - 1] * evnhere;
    if (d % 2 == 1) par ^= 1;
  }
  return ret;
}
long long solve(long long l, long long r, int kmx) {
  long long ret = r - l + 1;
  if (kmx == 0) {
    ret -= calcodd(r + 1) - calcodd(l);
    for (int k = 2; k <= MAXK; k += 2) ret -= calc(r + 1, k) - calc(l, k);
  } else {
    for (int k = (kmx + 1); k <= (MAXK); ++k)
      ret -= calc(r + 1, k) - calc(l, k);
  }
  return ret;
}
void run() {
  int nq;
  scanf("%d", &nq);
  for (int qi = (0); qi < (nq); ++qi) {
    long long l, r;
    int k;
    scanf("%lld%lld%d", &l, &r, &k);
    printf("%lld\n", solve(l, r, k));
  }
}
int main() {
  precalc();
  run();
  return 0;
}