题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1597
//用C++交能过,G++交就不能过,不知道为什么
#include<stdio.h>
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n,i=1;
scanf("%d",&n);
while(n>i)
{
n-=i;
i++;
}
n=n%9;
if(n) printf("%d\n",n);
else printf("9\n");
}
return 0;
}