T = int(input()) for _ in range(T): S = [int(x) for x in input()] lp_num = len(S) - 1 for _ in range(lp_num): a = [0] * (len(S) -1) b = sum([[x,x] for x in S], [])[1:-1] for i, num in enumerate(b): a[i//2] += b[i] S = [x if x < 10 else sum(divmod(x, 10)) for x in a] print(S[0])