T = int(raw_input()) for i in range(0, T): S = raw_input() while len(S) != 1: newS = '' for i in range(0, len(S)-1): n = int(S[i])+int(S[i+1]) if n >= 10: n = int(str(n)[0])+int(str(n)[1]) newS = newS + str(n) S = newS print S