#include int main(){ int n,i,s,t,u,a; scanf("%d",&n); for(i = 0; i < n; i++){ scanf("%d", &s); while(s>9){ t=s; s=0; u = 1; while(t > 9){ a = t%10 + (t/10) % 10; s += a>9 ? (a/10+a%10)*u : a*u; u *= 10; t /= 10; } } printf("%d\n",s); } return 0; }