#include<iostream>
using namespace std;
int main()
{
int t,b,n;
cin>>t;
while(t--)
{
cin>>b;
n=1;
while(b>n)//n代表第几个串
{
b-=n;
n++;
}
if(b%9==0)//b在一个串中的位置
cout<<9<<endl;
else
cout<<b%9<<endl;
}
return 0;
}
#include<iostream>
using namespace std;
int main()
{
int t,b,n;
cin>>t;
while(t--)
{
cin>>b;
n=1;
while(b>n)//n代表第几个串
{
b-=n;
n++;
}
if(b%9==0)//b在一个串中的位置
cout<<9<<endl;
else
cout<<b%9<<endl;
}
return 0;
}