# -*- coding: utf-8 -*- import sys,copy,math,heapq,itertools as it,fractions,re,bisect,collections as coll def pascal(n): line = [1] for k in xrange(n): line.append(line[k]*(n - k)/(k + 1)) return line T = int(raw_input()) for loop in xrange(T): S = raw_input() N = len(S) if N == 1: print S continue p = pascal(N - 1) X = 0 for i, s in enumerate(S): X += int(s)*p[i] ans = 0 for x in str(X): ans = ans + int(x) if ans >= 10: ans = ans%10 + 1 print ans