def solve(): S = list(map(int, input())) l = len(S) for i in range(l - 1, 0, -1): for j in range(i): S[j] += S[j + 1] if S[j] >= 10: S[j] = S[j] % 10 + 1 print(S[0]) for _ in range(int(input())): solve()