def sum(x,y): if int(x) + int(y) < 10: return int(x)+int(y) else: return (int(x)+int(y))//10 + (int(x)+int(y))%10 n = int(input()) for i in range(n): num = list(input()) while len(num) > 1: ls= [] for i in range(len(num)-1): ls.append(sum(num[i], num[i+1])) num = ls print(ls[0])