exec(compile("""x=lambda a,b:int(a)+int(b) for _ in[0]*int(input()): s=input() while len(s)>1:s="".join(str(x(i,j)%10+x(i,j)//10)for i,j in zip(s[:],s[1:])) print(s)""",'','exec',optimize=2))