#include <iostream>
#define long long long
const int maxn = 16;
const int maxk = 9;
const int maxs = 135;
using namespace std;
long dp[maxn+1][maxk+1][maxs+1];
void init()
{
for (int i=0; i<maxn; i++)
{
for (int j=0; j<maxk; j++)
{
for (int z=0; z<maxs; z++)
{
dp[i][j][z] = -1;
}
}
}
}
long cdp(int n,int d,int k)
{
if (dp[n][d][k]!=-1)
{
return dp[n][d][k];
}
else
{
if (k<0)
{
return 0;
exit(0);
}
else
if (n==0)
dp[n][d][k]=0;
else
if ((n==1) and (d==k) and (0<=k) and (9>=k))
dp[n][d][k]=1;
else
if ((n==1) and ((k!=d) or (k>9)))
dp[n][d][k]=0;
else
{
dp[n][d][k] = 0;
for (int i=0; i<=9; i++)
{
dp[n][d][k]+=cdp(n-1,i,k-d);
}
}
return dp[n][d][k];
}
}
long aa,bb,res1,res2,a[maxn+1],b[maxn+1];
int s,ss;
void tach()
{
a[0] = 0;
b[0] = 0;
do
{
a[0]++;
a[a[0]] = aa%10;
aa = aa/10;
}
while (aa!=0);
do
{
b[0]++;
b[b[0]] = bb%10;
bb = bb/10;
}
while (bb!=0);
}
void solve()
{
cin >> aa >> bb >> ss;
aa--;
tach();
res1 = 0;
s = ss;
for (int i=0; i<=a[a[0]]; i++)
{
res1 += cdp(a[0],i,s);
}
s -= a[1];
for (int i=a[0]-1; i>=1; i--)
{
for (int j=a[i]+1; j<=9; j++)
{
res1 -= cdp(i,j,s);
}
s = s-a[i];
}
res2 = 0;
s = ss;
for (int i=0; i<=b[b[0]]; i++)
{
res2 += cdp(b[0],i,s);
}
s -= b[1];
for (int i=b[0]-1; i>=1; i--)
{
for (int j=b[i]+1; j<=9; j++)
{
res2 -= cdp(i,j,s);
}
s = s-b[i];
}
cout << res2-res1;
}
int main() {
init();
int t;
cin >> t;
for (int i = 1; i<=t; i++)
{ solve(); }
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojZGVmaW5lIGxvbmcgbG9uZyBsb25nCmNvbnN0IGludCBtYXhuID0gMT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