import math def add(x, y): z = x + y if z >= 10: return z % 10 + z // 10 else: return z def shrink(x): if len(x) == 1: return x[0] else: r = [add(x[i], x[i+1]) for i in range(len(x)-1)] return shrink(r) T = int(input()) S = [[int (j) for j in list(input())] for i in range(T)] for s in S: print(shrink(s))