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