for _ in[0]*int(input()): s=input() while len(s)>1:s="".join(str((int(i)+int(j))%10+(int(i)+int(j))//10)for i,j in zip(s[:],s[1:])) print(s)