t=int(input()) i = 0 for _ in [0]*t: s=input() while len(s)!=1: s2="" while i < len(s) - 1: t=int(s[i])+int(s[i+1]) if t//10!=0:t=t%10+t//10 s2+=str(t) i+=1 i = 0 s=s2 print(s)