import sys sys.setrecursionlimit(10**3 * 2) def debug(x, table): for name, val in table.items(): if x is val: print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr) return None def solve(): T = int(input()) for test in range(T): S = [int(i) for i in input()] # debug(S, locals()) ans = uranai(S) print(ans) def uranai(S): if len(S) == 1: return S[0] else: S = [S[i] + S[i + 1] for i in range(len(S) - 1)] for i in range(len(S)): if S[i] >= 10: S[i] = 1 + S[i] % 10 return uranai(S) if __name__ == '__main__': solve()