int f(int n) { if (n < 10) { return n; } return f((n % 10) + f(n / 10)); }
f(49) = f(13) = f(4) = 4.
for _ in range(int(input())): n = int(input()) print((n-1) % 9+1 if n else 0)
using namespace std; int num;
int main() { int T,i,total = 0; cin>>T; while(T–) {
cin>>num; total = num; while(total>=10){ total = 0; while(num){ total += num%10; num /= 10; } num = total; } cout<<total<<endl; } return 0;
}
if(sum<=9) return sum; else return f(f(sum));
T = int(input()) for i in range(T): n = int(input()) if n == 0: print(0) elif n % 9 != 0: print(n % 9) else: print(9)
f(49) = f(13) = f(4) = 4.
include
using namespace std;
int num;
int main()
{
int T,i,total = 0;
cin>>T;
while(T–)
{
}
if(sum<=9) return sum; else return f(f(sum));
T = int(input())
for i in range(T):
n = int(input())
if n == 0:
print(0)
elif n % 9 != 0:
print(n % 9)
else:
print(9)