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