def g(n): if n >= 10: n = int(str(n)[0])+int(str(n)[1]) if n >= 10: n = int(str(n)[0])+int(str(n)[1]) return str(n) def f(s): ss = "" for i in range(len(s) - 1): ss += g(int(s[i]+s[i+1])) return ss T = int(input()) for _ in range(T): s = input() while len(s) > 1: s = f(s) print(s)