#include <bits/stdc++.h>
using namespace std;
int main()
{
int indeks=1;
int digit[18];
/*
freopen("output.txt","w",stdout);
long long num=1,comp=10,sumdigit=0;
for(int temp=0;temp<18;temp++) digit[temp]=0;
while(sumdigit<=2000000000)
{
long long x=num;
x=x*x;
if(x<comp)
{
digit[indeks]++;
}
else
{
printf("digit[%d] = %d\n",indeks,digit[indeks]);
indeks++;
comp=comp*10;
digit[indeks]++;
}
sumdigit+=indeks;
num++;
}
printf("digit[%d] = %d\n",indeks,digit[indeks]);
*/
digit[1] = 3;
digit[2] = 6;
digit[3] = 22;
digit[4] = 68;
digit[5] = 217;
digit[6] = 683;
digit[7] = 2163;
digit[8] = 6837;
digit[9] = 21623;
digit[10] = 68377;
digit[11] = 216228;
digit[12] = 683772;
digit[13] = 2162278;
digit[14] = 6837722;
digit[15] = 21622777;
digit[16] = 68377223;
digit[17] = 26249855;
int tc;
scanf("%d",&tc);
while(tc--)
{
int x,indeks=1;
scanf("%d",&x);
int prefix=0;
while(x>digit[indeks]*indeks)
{
x-=digit[indeks]*indeks;
prefix+=digit[indeks];
indeks++;
}
x--;
int bucket=x/indeks;
int pos=x%indeks;
long long num=prefix+bucket+1;
num=num*num;
string s=to_string(num);
printf("%c %lld\n",s[pos],num);
}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgbWFpbigpCnsKCWludCBpbmRla3M9MTsKCWludCBkaWdpdFsxOF07CgkvKgoJZnJlb3Blbigib3V0cHV0LnR4dCIsInciLHN0ZG91dCk7Cglsb25nIGxvbmcgbnVtPTEsY29tcD0xMCxzdW1kaWdpdD0wOwoJZm9yKGludCB0ZW1wPTA7dGVtcDwxODt0ZW1wKyspCWRpZ2l0W3RlbXBdPTA7Cgl3aGlsZShzdW1kaWdpdDw9MjAwMDAwMDAwMCkKCXsKCQkKCQlsb25nIGxvbmcgeD1udW07CgkJeD14Kng7CgkJaWYoeDxjb21wKQoJCXsKCQkJ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