ans = [] for _ in range(int(input())) : s, t = set(input()), 2015 for c in s : t -= ord(c) ans.append(t) print('\n'.join(map(str, ans)))