def su2(k,l): a=k+l if a>9: r=a%10 a=1+r return a T=int(input()) S=[list(input()) for i in range (T)] #rint(S) for i in range(T): for j in range(len(S[i])): S[i][j]=int(S[i][j]) # print (S) j=len(S[i]) # print (j) while j > 2: for k in range(1,len(S[i])-j-1): S[i][k-1]=su2(S[i][k-1], S[i][k]) j-=1 if j==2: S[i][0]=su2(S[i][0],S[i][1]) print(S[i][0])