def f(a, b): c = a + b if c >= 10: return 1 + (c % 10) else: return c t = int(input()) for i in range(t): s = list(map(int, ''.join(input()))) while len(s) > 1: for j in range(len(s) - 1): s[j] = f(s[j], s[j + 1]) s.pop() print(*s)