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