def solve(S): slst = [ord(c) - ord('0') for c in S] while len(slst) > 1: nextlst = [] for i in range(len(slst) - 1): sn = slst[i] + slst[i + 1] if (sn >= 10): sn = sn % 10 + (sn // 10) % 10 nextlst += [sn] #print(nextlst) slst = nextlst print(slst[0]) T = int(input()) for i in range(T): S = input() solve(S)