t=int(input()) s=[[int(i) for i in input()] for j in'.'*t] for i in s: while len(i)>1: i=list(((x+y)%10)+((x+y)>9) for x,y in (zip(i[1:],i))) print(i[0])