#include<iostream>
#include<cmath>
using namespace std;
int xc(long long int cy) {
int hy=-1;
for (;cy>=1;) {
cy = (cy + 1) / 10;
hy++;
}
return hy;
}
int main() {
int n;
cin >> n;
while (n--)
{
long long int m, x, y,cq=0;
int a, b;
cin >> x >> y >> m;
a = xc(x);
b = xc(y);
for (int i = a+1; i <b; i++) {
cq += pow(10, i);
}
if ((m + 1) * pow(10, a) - x > pow(10, a))
cq += pow(10, a);
else if ((m + 1) * pow(10, a) - x > 0)
cq += (m + 1) * pow(10, a) - 1 - x;
cout << cq << endl;
}
return 0;
}