t=int(input()) i = 0 st = [input() for i in range(t)] for s in st: 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)