import sys input=lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(10000) def f(S): if len(S)==1: return S[0] else: T=[] for i in range(len(S)-1): t=S[i]+S[i+1] if t>=10: t=t%10+1 T.append(t) return f(T) x=int(input()) for _ in range(x): print(f([int(s) for s in list(input())]))