import sys sys.setrecursionlimit(10 ** 3) def fortune_telling(S): if len(S) == 1: return print(S.pop()) else: fortune_S = [] for i in range(1, len(S)): plus = S[i-1] + S[i] fortune_S.append(plus // 10 + plus % 10) fortune_telling(fortune_S) def main(): n = int(input()) for _ in range(n): S = list(map(int, " ".join(input()).split())) fortune_telling(S) main()