def func(s): l = [] for i in range(len(s) - 1): p = s[i] + s[i+1] pp = p if p < 10 else int(str(p)[0]) + int(str(p)[1]) l.append(pp) return l t = int(input()) for i in range(t): s = list(map(int, list(input()))) while True: if len(s) == 1: print(*s) break s = func(s)