T=int(input()) out=[] for x in range(T): S=input() K=len(S) if(len(S)==1): out.extend(S) else: while(K>1): ans=[0]*(K-1) for i in range(K-1): ans[i]=int(S[i])+int(S[i+1]) if ans[i]>=10: ans[i]=ans[i]//10+ans[i]%10 S=ans K-=1 out.extend(str(ans[0])) for k in out: print(k)