st = [input() for i in range(int(input()))] for s in st: while len(s)!=1: s2="" s1 = [str(sum(divmod(int(s[i]) + int(s[i + 1]), 10))) for i in range(len(s) - 1)] s="".join(s1) print(s)