Solve the mystery.
Input:
First line contains a single integer denoting number of test cases(T).
Next T lines have one test case per line.
Each test case is a string of alphabets [a-z].

Output:
Print answer to each test case in an individual line.

Constraints:
1 ≤ T ≤ 100
1 ≤ |S| ≤ 100
a ≤ S[i] ≤ z

Problem Setter : Siddharth Seth

SAMPLE INPUT
5
malayalam
ariyama
alla
brook
kurruk

SAMPLE OUTPUT
121
-1
108
-1
114
def is_palin(s):
	slen = len(s)
	i = 0
	half = slen/2;
	while i < half:
		if s[i] != s[slen-i-1]:
			return False
		i += 1
	return True

def solve():
	t = input()
	for i in xrange(t):
		s = raw_input()
		if is_palin(s):
			print ord(s[len(s)/2])
		else:
			print '-1'
solve()