def solver(s): l = s while len(l) > 1: _l = [] for i in range(len(l)-1): tmp = int(l[i]) + int(l[i+1]) if tmp >= 10: tmp = 1 + (tmp - 10) _l.append(str(tmp)) l = _l print(l[0]) T = int(input().strip()) for i in range(T): solver(input().strip())