T = int(input()) def f(x, y): if x + y < 10: return x + y else: sho, amari = divmod(x + y, 10) return sho + amari ansl = [] for _ in range(T): S = list(map(lambda x: int(x),list(input()))) M = len(S) for i in range(M - 1): nexS = [] for j in range(M - 1 - i): x, y = S[j], S[j + 1] nexS.append(f(x, y)) S = nexS ansl.append(S[0]) print(*ansl, sep='\n')