t = int(input()) for _ in range(t): s = list(str(input())) s = [int(i) for i in s] while len(s) > 1: temp = [] for i in range(len(s)-1): if s[i]+s[i+1] < 10: temp.append(s[i]+s[i+1]) else: temp.append(1+(s[i]+s[i+1])%10) s = temp print(s[0])