The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.

The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $a$ comes earlier than word $b$ in the dictionary if one of the following conditions hold:

the first letter of $a$ is less than the first letter of $b$;

the first letters of $a$ and $b$ are the same, and the second letter of $a$ is less than the second letter of $b$.

So, the dictionary looks like that:

Word $1$: ab

Word $2$: ac

...

Word $25$: az

Word $26$: ba

Word $27$: bc

...

Word $649$: zx

Word $650$: zy

You are given a word $s$ from the Berland language. Your task is to find its index in the dictionary.


-----Input-----

The first line contains one integer $t$ ($1 \le t \le 650$) — the number of test cases.

Each test case consists of one line containing $s$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).


-----Output-----

For each test case, print one integer — the index of the word $s$ in the dictionary.


-----Examples-----

Input
7
ab
ac
az
ba
bc
zx
zy
Output
1
2
25
26
27
649
650


-----Note-----

None

Source: codeforces | Difficulty: EASY
Tags: Combinatorics

Mathematics


Solutions:
def main():
	arr = []
	for i in range(97, 97 + 26):
		for j in range(97, 97 + 26):
			if i == j:
				continue
			arr.append(chr(i) + chr(j))
	t = int(input())
	for _ in range(t):
		s = input()
		print(arr.index(s) + 1)
main()


dic = []
for c1 in 'abcdefghijklmnopqrstuvwxyz':
	for c2 in 'abcdefghijklmnopqrstuvwxyz':
		if c1 != c2:
			dic.append(c1 + c2)
for _ in range(int(input())):
	print(dic.index(input()) + 1)


for _ in range(int(input())):
	s = input()
	a = s[0]
	b = s[1]
	x = ord(a) - 97
	y = ord(b) - 97
	ans = x * 26
	if x > y:
		ans = ans + y - x + 1
	else:
		ans = ans + y - x
	print(ans)


for _ in range(int(input())):
	a = input()
	ans = 0
	f = ord(a[0]) - 97
	ans = f * 25
	s = ord(a[1]) - 97
	if s > f:
		ans += s
	else:
		ans += s + 1
	print(ans)


t = int(input())
for _ in range(t):
	s = input()
	ans = (ord(s[0]) - 96 - 1) * 25
	if s[1] < s[0]:
		temp = ord(s[1]) - 96
	else:
		temp = ord(s[1]) - 96 - 1
	ans += temp
	print(ans)


r = range(97, 123)
a = [chr(x) + chr(y) for x in r for y in r if x ^ y]
for s in [*open(0)][1:]:
	print(a.index(s[:-1]) + 1)


def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return s

def invr():
	return map(int, input().split())
T = inp()

def solve(d):
	w = insr()
	return d[w]

def generateDictionary():
	d = {}
	c = 1

	def getChar(k):
		return chr(ord('a') + k)
	for i in range(26):
		for j in range(26):
			if i == j:
				continue
			d[getChar(i) + getChar(j)] = c
			c += 1
	return d
d = generateDictionary()
for t in range(1, T + 1):
	print('{}'.format(solve(d)))


d = {}
s = 'abcdefghijklmnopqrstuvwxyz'
count = 0
for i in s:
	for j in s:
		if i != j:
			count += 1
			d[i + j] = count
for i in range(int(input())):
	print(d[input()])


def value(word):
	number = 25 * (ord(word[0]) - 97) + (ord(word[1]) - 96)
	if ord(word[0]) < ord(word[1]):
		number -= 1
	return number

def main():
	n = int(input())
	data = []
	for i in range(n):
		word = input()
		data.append(word)
	for word in data:
		print(value(word))
main()


n = int(input())
letters = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
for i in range(n):
	lst = []
	s = str(input())
	for _ in s:
		lst.append(_)
	if letters[lst[-1]] > letters[lst[0]]:
		print(letters[lst[0]] * 25 + letters[lst[-1]])
	else:
		print(letters[lst[0]] * 25 + letters[lst[-1]] + 1)


def find_number(l):
	(one, two) = (ord(l[0]) - 96, ord(l[1]) - 96)
	sum = 0
	sum = 25 * one - 24
	if one < two:
		return sum + two - 2
	else:
		return sum + two - 1
for i in range(int(input())):
	print(find_number(list(input())))


for i in range(int(input())):
	s = input()
	val = ord(s[0]) - 96
	start_index = 1 + (val - 1) * 25
	if ord(s[1]) < ord(s[0]):
		val2 = ord(s[1]) - 97
	else:
		val2 = ord(s[1]) - 97 - 1
	print(start_index + val2)


def solve(s):
	left = ord(s[0]) - ord('a')
	right = ord(s[1]) - ord('a') + 1
	if left < right:
		right -= 1
	res = left * 25 + right
	return res
t = int(input())
for _ in range(t):
	s = input()
	print(solve(s))


alphabet = 'qwertyuiopasdfghjklzxcvbnm'
my_list = []
for x in alphabet:
	for y in alphabet:
		if x == y:
			continue
		else:
			my_list.append(x + y)
my_list.sort()

def input_strings():
	input_data = []
	number_cases = int(input())
	for i in range(number_cases):
		input_data.append(input())
	return input_data
data = input_strings()
for string in data:
	print(my_list.index(string) + 1)


t = int(input())
for i in range(t):
	s = input()
	l1 = ord(s[0]) - ord('a')
	ans = 26 * l1
	l2 = ord(s[1]) - ord('a')
	ans += l2
	ans -= ord(s[0]) - ord('b')
	if ord(s[0]) < ord(s[1]):
		ans -= 1
	print(ans)


from bisect import bisect_left, bisect_right
from sys import stdin, setrecursionlimit
from itertools import count, accumulate
from collections import defaultdict, deque, Counter
from functools import reduce, lru_cache
from operator import xor, add
lines = stdin.readlines()
lines.reverse()
setrecursionlimit(10 ** 8)

def input():
	return lines.pop().strip('\n')
hashi = defaultdict(int)
cnt = 1
for i in range(26):
	for j in range(26):
		if i != j:
			hashi[chr(i + ord('a')) + chr(j + ord('a'))] = cnt
			cnt += 1
t = int(input())
while t:
	s = input()
	print(hashi[s])
	t -= 1


for _ in range(int(input())):
	s = input()
	sum = 0
	n = ord(s[0]) - 96
	m = ord(s[1]) - 96
	if n < m and n != 1:
		print(25 * (n - 1) + m - 1)
	elif n == 1:
		print(m - 1)
	else:
		print(25 * (n - 1) + m)


n = int(input())
for i in range(n):
	a = input()
	if ord(a[1]) > ord(a[0]):
		print((ord(a[0]) - 97) * 25 + (ord(a[1]) - 97))
	else:
		print((ord(a[0]) - 97) * 25 + (ord(a[1]) - 96))


a = int(input())
for w in range(a):
	s = input()
	(a, b) = (s[0], s[1])
	oa = ord(a) - 96
	ob = ord(b) - 96
	if oa > ob:
		print((oa - 1) * 25 + ob)
	else:
		print((oa - 1) * 25 + (ob - 1))


t = int(input())
for x in range(t):
	s = input()
	char1 = s[0]
	char2 = s[1]
	num1 = ord(char1) - 96
	num2 = ord(char2) - 96
	if num1 < num2:
		print(f'{(num1 - 1) * 25 + num2 - 1}')
	else:
		print(f'{(num1 - 1) * 25 + num2}')


dic = {}
for i in range(1, 27):
	dic[chr(96 + i)] = i
t = int(input())
for i in range(t):
	wor = input()
	if wor[1] > wor[0]:
		if wor[0] == 'a':
			print(dic[wor[0]] + (dic[wor[1]] - 2))
		else:
			print((dic[wor[0]] - 1) * 25 + 1 + (dic[wor[1]] - 2))
	else:
		print((dic[wor[0]] - 1) * 25 + 1 + (dic[wor[1]] - 1))


t = int(input())
for i in range(t):
	a = input()
	x = 25 * (ord(a[0]) - ord('a'))
	y = ord(a[1]) - ord('a') + 1
	if a[1] > a[0]:
		print(x + y - 1)
	else:
		print(x + y)


n = int(input())
for i in range(n):
	d = input()
	(a, b) = (ord(d[0]) - 96, ord(d[1]) - 96)
	if a < b:
		b = b - 1
	print(25 * (a - 1) + b)


(x, y, z) = ('abcdefghijklmnopqrstuvwxyz', {}, 0)
for a in x:
	for b in x:
		if a == b:
			continue
		z += 1
		y[a + b] = z
for _ in range(int(input())):
	print(y[input()])


import math
t = int(input())
alphabet = {'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5, 'f': 6, 'g': 7, 'h': 8, 'i': 9, 'j': 10, 'k': 11, 'l': 12, 'm': 13, 'n': 14, 'o': 15, 'p': 16, 'q': 17, 'r': 18, 's': 19, 't': 20, 'u': 21, 'v': 22, 'w': 23, 'x': 24, 'y': 25, 'z': 26}
for _ in range(t):
	string = input()
	res = (alphabet[string[0]] - 1) * 25 + alphabet[string[1]]
	if not alphabet[string[1]] < alphabet[string[0]]:
		res -= 1
	print(res)


for (x, y, _) in [*open(0)][1:]:
	print(25 * ord(x) + ord(y) - (y > x) - 2521)


t = int(input())
res = []
for i in range(t):
	s = input()
	(s1, s2) = (s[0], s[1])
	add = ord(s1) - ord(s2)
	if add > 0:
		res.append(25 * (ord(s1) - 97) + ord(s2) - 96)
	else:
		res.append(25 * (ord(s1) - 97) + ord(s2) - 96 - 1)
for i in res:
	print(i)


t = int(input())
for _ in range(t):
	s = input()
	stIdx = 25 * (ord(s[0]) - ord('a')) + 1
	ans = stIdx + (ord(s[1]) - ord('a'))
	if s[1] > s[0]:
		ans -= 1
	print(ans)


for i in range(int(input())):
	s = input()
	(f, s) = (s[0], s[1])
	cnt = 0
	cnt = cnt + (ord(f) - ord('a')) * 25
	if ord(f) < ord(s):
		cnt = cnt + (ord(s) - ord('a'))
	else:
		cnt = cnt + (ord(s) - ord('a')) + 1
	print(cnt)


for i in range(int(input())):
	x = input()
	ans = 0
	a = ord(x[0]) - 96
	b = ord(x[1]) - 96
	if b > a:
		ans = (a - 1) * 25 + b - 1
	else:
		ans = (a - 1) * 25 + b
	print(ans)


for i in range(int(input())):
	string = input()
	ans = 25 * (ord(string[0]) - 97)
	if string[0] < string[1]:
		ans += ord(string[1]) - 97
	else:
		ans += ord(string[1]) - 96
	print(ans)


n = int(input())
d = {}
k = 97
for j in range(26):
	d[chr(k)] = j
	k += 1
for i in range(n):
	s = input()
	c = 0
	c += 25 * d[s[0]]
	if s[1] < s[0]:
		c += d[s[1]] + 1
	else:
		c += d[s[1]]
	print(c)


t = int(input())
arr = []
for i in range(t):
	s = input()
	x = 1 + (ord(s[0]) - 97) * 25
	if ord(s[0]) < ord(s[1]):
		y = ord(s[1]) - 98
	else:
		y = ord(s[1]) - 97
	arr.append(x + y)
for i in arr:
	print(i)


n = int(input())
result = []
for i in range(n):
	alfa = 'a b c d e f g h i j k l m n o p q r s t u v w x y z'.split()
	aux = input()
	first = aux[0]
	sec = aux[1]
	first_index = alfa.index(first)
	alfa.remove(first)
	sec_index = alfa.index(sec)
	res = first_index * 25 + sec_index + 1
	result.append(res)
for res in result:
	print(res)


a = int(input())
for i in range(a):
	b = input()
	if b[0] < b[1]:
		print(ord(b[0]) % 97 * 26 + (ord(b[1]) - ord(b[0])))
	else:
		print(ord(b[0]) % 97 * 26 - (ord(b[0]) - ord(b[1]) - 1))


n = int(input())

def solve(n):
	for i in range(n):
		item = input()
		firstBit = (ord(item[0]) - ord('a')) * 25
		if item[0] == 'a':
			secondBit = ord(item[1]) - ord('a')
		elif item[1] > item[0]:
			secondBit = ord(item[1]) - ord('a')
		elif item[1] < item[0]:
			secondBit = ord(item[1]) - ord('a') + 1
		print(f'{firstBit + secondBit}')
solve(n)


t = int(input())
for i in range(t):
	word = input()
	firstLetter = ord(word[0]) - 96
	lastLetter = ord(word[1]) - 96
	group = (firstLetter - 1 % 26) * 25
	index = group + lastLetter
	if lastLetter > firstLetter:
		index -= 1
	print(index)


t = int(input())
while t > 0:
	s = str(input())
	dic0 = {'a': 0, 'b': 26, 'c': 51, 'd': 76, 'e': 101, 'f': 126, 'g': 151, 'h': 176, 'i': 201, 'j': 226, 'k': 251, 'l': 276, 'm': 301, 'n': 326, 'o': 351, 'p': 376, 'q': 401, 'r': 426, 's': 451, 't': 476, 'u': 501, 'v': 526, 'w': 551, 'x': 576, 'y': 601, 'z': 626}
	dic1 = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
	x = dic0[s[0]] + dic1[s[1]]
	if s[0] == 'a':
		print(x)
	elif dic1[s[0]] - dic1[s[1]] < 0:
		print(x - 1)
	else:
		print(x)
	t = t - 1


t = int(input())
alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
for _ in range(t):
	w = str(input())
	ans = alphabet.index(w[0]) * 25
	if alphabet.index(w[1]) < alphabet.index(w[0]):
		ans += alphabet.index(w[1]) + 1
	else:
		ans += alphabet.index(w[1])
	print(ans)


for i in range(int(input())):
	(a, b) = map(ord, input())
	print(25 * a + b - 2522 + (a > b))


t = int(input())
a = []
for i in range(26):
	for j in range(26):
		if i != j:
			a.append(str(chr(97 + i)) + str(chr(97 + j)))
a.sort()
for i in range(t):
	s = input()
	print(a.index(s) + 1)


tc = int(input())
for case in range(tc):
	(a, b) = list(input())
	ad = ord(a) - ord('a')
	bd = ord(b) - ord('a')
	nas = ad * 25 + bd + (1 if b < a else 0)
	print(nas)


def let(n):
	base = ord('a')
	return chr(n + base)
cnt = 1
d = {}
for i in range(26):
	for j in range(26):
		if i == j:
			continue
		ch1 = let(i)
		ch2 = let(j)
		d[ch1 + ch2] = cnt
		cnt += 1
t = int(input())
for tc in range(t):
	k = input()
	print(d[k])


ch = 'abcdefghijklmnopqrstuvwxyz'
count = 1
d = {}
for c1 in ch:
	for c2 in ch:
		if c1 == c2:
			continue
		d[f'{c1}{c2}'] = count
		count += 1
for i in range(int(input())):
	s = input()
	print(d[s])


t = int(input())
for _ in range(t):
	s = input()
	a = ord(s[0]) - 97
	b = ord(s[1]) - 97
	if b < a:
		print(a * 25 + b + 1)
	else:
		print(a * 25 + b)


t = int(input())
for _ in range(t):
	n = input()
	a = ord('a')
	x = ord(n[0])
	y = ord(n[1])
	ans = (x - a) * 26 + (y - a) - (x - a)
	if x > y:
		ans += 1
	print(ans)


def helper(word):
	partition = ord(word[0]) - ord('a')
	additional = ord(word[-1]) - ord('a')
	if additional < partition:
		additional += 1
	res = partition * 25 + additional
	return res

def main():
	n = int(input())
	for i in range(n):
		word = input()
		idx = helper(word)
		print(idx)
main()


for t in range(int(input())):
	s = input()
	d = {}
	c = 0
	for i in range(ord('a'), ord('z') + 1):
		d[chr(i)] = c
		c += 1
	ans = d[s[0]] * 26 + d[s[1]] - d[s[0]]
	if s[0] > s[1]:
		print(ans + 1)
	else:
		print(ans)


t = int(input())
let = []
alpha = 'abcdefghijklmnopqrstuvwxyz'
rank = {}
for i in range(t):
	let.append(input())
count = 0
for i in range(len(alpha)):
	for z in range(len(alpha)):
		if z != i:
			count = count + 1
			rank[alpha[i] + alpha[z]] = count
for i in let:
	print(rank[i])


for t in range(int(input())):
	s = input()
	index = (ord(s[0]) - ord('a')) * 25
	index = index + (ord(s[1]) - ord('a')) * 1
	if s[0] > s[1]:
		index += 1
	print(index)


for _ in range(int(input())):
	w = input()
	(a, b) = (ord(w[0]), ord(w[1]))
	if a < b:
		print(25 * (a - 97) + b - 97)
	else:
		print(25 * (a - 97) + b - 97 + 1)


for i in range(int(input())):
	s = list(input())
	print((ord(s[0]) - 97) * 25 + (ord(s[1]) - 96) + (-1 if s[0] < s[1] else 0))


from os import remove
t = int(input())
a = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
for i in range(t):
	s = str(input())
	if s[0] == a[0]:
		print(a.index(s[1]))
	elif s == 'bc':
		print(27)
	else:
		b = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
		b.remove(s[0])
		print(25 * a.index(s[0]) + (b.index(s[1]) + 1))


def alphabet_order(s):
	if ord(s[0]) < ord(s[1]):
		return (ord(s[0]) - 97) * 26 + (ord(s[1]) - ord(s[0]))
	elif ord(s[0]) < ord(s[1]) and s[0] != 'a':
		return (ord(s[0]) - 97) * 26 + (ord(s[1]) - ord(s[0]) - 1)
	return (ord(s[0]) - 97) * 26 + (ord(s[1]) - ord(s[0]) + 1)
n = int(input())
while n > 0:
	s = str(input())
	print(alphabet_order(s))
	n -= 1


T = int(input())
bd = {}
c = 0
for x in 'abcdefghijklmnopqrstuvwxyz':
	for y in 'abcdefghijklmnopqrstuvwxyz':
		if x != y:
			c += 1
			bd[x + y] = c
for t in range(T):
	print(bd[input()])


num = int(input())
count = 0
while count < num:
	count += 1
	fin = 0
	string = input()
	first = string[0]
	second = string[1]
	fin = 25 * (ord(first) - 97) + (ord(second) - 96)
	if ord(first) < ord(second):
		fin -= 1
	print(fin)


import math
t = int(input())
for _ in range(t):
	s = input()
	x = ord(s[0])
	y = ord(s[1])
	if x > y:
		p = 25 * (x - 97) + (y - 96)
	else:
		p = 25 * (x - 97) + (y - 96) - 1
	print(p)


import math
rounds = int(input())
for _ in range(rounds):
	s = input()
	cycle = ord(s[0]) - ord('a')
	ad = -1 if s[1] > s[0] else 0
	print(cycle * 25 + max(abs(ord(s[1]) - ord('a') + 1 + ad), 1))


t = int(input())
letters = 'abcdefghijklmnopqrstuvwxyz'
words = []
for i in range(len(letters)):
	for letter in letters:
		words.append(letter + letters[i])
all_words = sorted(words)
berland = []
for word in all_words:
	if word[0] != word[1]:
		berland.append(word)
for i in range(t):
	text = input()
	print(berland.index(text) + 1)


def index(s):
	l1 = s[0]
	l2 = s[1]
	alphabet = {1: 'a', 2: 'b', 3: 'c', 4: 'd', 5: 'e', 6: 'f', 7: 'g', 8: 'h', 9: 'i', 10: 'j', 11: 'k', 12: 'l', 13: 'm', 14: 'n', 15: 'o', 16: 'p', 17: 'q', 18: 'r', 19: 's', 20: 't', 21: 'u', 22: 'v', 23: 'w', 24: 'x', 25: 'y', 26: 'z'}
	for keys in alphabet:
		if alphabet[keys] == l1:
			num1 = keys
		elif alphabet[keys] == l2:
			num2 = keys
	if num1 > num2:
		result = (num1 - 1) * 25 + num2
	else:
		result = (num1 - 1) * 25 + (num2 - 1)
	return result
t = int(input())
for i in range(t):
	stra = list(input())
	print(index(stra))


my_dict = [chr(i) for i in range(97, 123)]
for i in range(int(input())):
	s = input()
	x = 1 + (ord(s[0]) - 97) * 25
	if s[1] < s[0]:
		print(x + my_dict.index(s[1]))
	else:
		print(x + my_dict.index(s[1]) - 1)


t = int(input())
while t > 0:
	t -= 1
	line = input().split(' ')
	word = line[0]
	ans = (ord(word[0]) - 97) * 25
	if ord(word[0]) < ord(word[1]):
		print(ans + ord(word[1]) - 97)
	else:
		print(ans + ord(word[1]) - 96)


n = int(input())
for i in range(n):
	p = input()
	a = ord(p[0]) - 97
	b = ord(p[1]) - 96
	p = a * 26 + b
	if a < b:
		print(p - (1 + a))
	elif a > b or a == b:
		print(p - a)


for _ in range(int(input())):
	s = input()
	m = {}
	for i in range(26):
		m[chr(97 + i)] = i
	ans = 0
	ans = 25 * m[s[0]]
	if m[s[1]] > m[s[0]]:
		ans += m[s[1]]
	else:
		ans += m[s[1]] + 1
	print(ans)


for _ in range(int(input())):
	s = input()
	f = ord(s[0]) - 96
	s = ord(s[1]) - 96
	if s > f:
		print(25 * (f - 1) + (s - 1))
	else:
		print(25 * (f - 1) + s)


t = int(input())
for x in range(t):
	s = input()
	p = ord(s[0])
	p = p - 96
	p = p * 25
	min = p - 24
	q = ord(s[-1])
	q -= 97
	if s[0] > s[1]:
		print(min + q)
	else:
		print(min + q - 1)


def main():
	t = int(input())
	for LOVE in range(t):
		s = input()
		print((ord(s[0]) - 97) * 25 + (ord(s[1]) - 97 + 1) - (ord(s[0]) <= ord(s[1])))
main()


def sol():
	n = int(input())
	import math
	for i in range(n):
		s = input()
		y1 = int(ord(s[0]) - 97)
		y2 = int(ord(s[1]) - 97)
		if y1 < y2:
			print(y1 * 25 + y2)
		else:
			print(y1 * 25 + y2 + 1)
sol()


for _ in range(int(input())):
	s = input()
	i = ord(s[0]) - 97
	j = ord(s[1]) - 97
	print(1 + 25 * i + j - (j > i))


t = int(input())
a = ord('a')
for tt in range(t):
	s = input()
	x = (ord(s[0]) - a) * 25
	if ord(s[1]) < ord(s[0]):
		x += ord(s[1]) - a
	else:
		x += ord(s[1]) - a - 1
	print(x + 1)


t = int(input())
out = ''
letters = 'abcdefghijklmnopqrstuvwxyz'
for _ in range(t):
	word = input()
	pos = letters.index(word[0]) * 25 + letters.index(word[1]) + 1
	if letters.index(word[0]) < letters.index(word[1]):
		pos -= 1
	out += str(pos) + '\n'
print(out)


charList = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
listResult = []
for i in range(26):
	for j in range(26):
		if charList[i] is not charList[j]:
			listResult.append(charList[i] + charList[j])
inputList = []
testCase = int(input())
for i in range(testCase):
	inputList.append(input())
for i in range(testCase):
	print(listResult.index(inputList[i]) + 1)


arr = []
for i in range(97, 123):
	for j in range(97, 123):
		if chr(i) != chr(j):
			arr.append(chr(i) + chr(j))
t = int(input())
for k in range(t):
	s = input()
	x = arr.index(s)
	print(x + 1)


for _ in range(int(input())):
	a = 'abcdefghijklmnopqrstuvwxyz'
	s = input()
	x = ord(s[0]) - 97
	x = x * 25
	c = 0
	for i in a:
		if i == s[1]:
			break
		if i != s[0]:
			c += 1
	print(x + c + 1)


j = []
for i in range(int(input())):
	x = input()
	nl = [x for x in range(97, 97 + 26)]
	nl.remove(ord(x[0]))
	print(25 * (ord(x[0]) - 97) + nl.index(ord(x[1])) + 1)
for i in j:
	print(i)


for _ in range(int(input())):
	s = input()
	a = ord(s[0])
	b = ord(s[1])
	res = 25 * (a - 97) + (b - 97) + (a > b)
	print(res)


d = {}
x = 0
for i in range(ord('a'), ord('z') + 1):
	s = chr(i)
	for j in range(ord('a'), ord('z') + 1):
		if i == j:
			continue
		s += chr(j)
		x += 1
		d[s] = x
		s = chr(i)
for t in range(int(input())):
	print(d[input()])


dict = {}
count = 0
for first in 'abcdefghijklmnopqrstuvwxyz':
	for second in 'abcdefghijklmnopqrstuvwxyz':
		if first != second:
			count += 1
			char = first + second
			dict[char] = count
n = int(input())
for i in range(n):
	lst = input()
	print(dict[lst])


l1 = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
l2 = l1
l3 = []
for i in range(len(l1)):
	for j in range(len(l1)):
		if l1[i] != l2[j]:
			l3.append(l1[i] + l2[j])
t = int(input())
for h in range(t):
	x = input()
	print(l3.index(x) + 1)


n = int(input())
while n > 0:
	s = input()
	if ord(s[1]) > ord(s[0]):
		print(25 * (ord(s[0]) - 97) + (ord(s[1]) - 97))
	else:
		print(25 * (ord(s[0]) - 97) + (ord(s[1]) - 96))
	n = n - 1


for l in range(int(input())):
	s = input()
	s.lower()
	a = ord(s[0])
	b = ord(s[1])
	val = 25 * (a - 97) + (b - 96)
	if a < b:
		val = val - 1
	print(val)


list(map(lambda s: print(ord(s[0]) * 25 + ord(s[1]) - 2522 + (s[0] > s[1])), [*open(0)][1:]))


tc = int(input())
list1 = []
list2 = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
for i in list2:
	for j in list2:
		if i != j:
			list1.append(i + j)
dict1 = {}
for i in range(1, 651):
	dict1[list1[i - 1]] = i
for _ in range(tc):
	s = input()
	print(dict1[s])


from sys import stdin, stdout
from collections import defaultdict
input = stdin.readline
from random import randint
import math
import sys
for _ in range(int(input())):
	s = input().strip()
	f = ord(s[0]) - ord('a') + 1
	second = ord(s[1]) - ord('a')
	if ord(s[0]) > ord(s[1]):
		second += 1
	print(25 * (f - 1) + second)


def sol(s):
	x = ord(s[0]) - ord('a')
	y = ord(s[1]) - ord('a')
	if x - y > 0:
		return 25 * x + y + 1
	else:
		return 25 * x + y
t = int(input())
for _ in range(t):
	s = input()
	print(sol(s))


t = int(input())
if t >= 1 and t <= 10000:
	for i in range(t):
		ui = str(input())
		qw = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
		j = ui[0]
		d = ui[1]
		for i in range(len(qw)):
			if qw[i] == j:
				h = i
			if qw[i] == d:
				c = i
		if h < c:
			print(25 * h + c)
		else:
			print(25 * h + c + 1)


arr = list('abcdefghijklmnopqrstuvwxyz')
xrr = {}
k = 1
for i in range(26):
	for j in range(26):
		if i != j:
			xrr[arr[i] + arr[j]] = k
			k += 1
t = int(input())
for i in range(t):
	s = input()
	print(xrr[s])


n = int(eval(input()))
for i in range(n):
	word = input()
	wd_dict = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
	res = 0
	res += wd_dict.index(word[0]) * 25
	if word[0] < word[1]:
		res += wd_dict.index(word[1])
	else:
		res += wd_dict.index(word[1]) + 1
	print(res)


letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
new_letters = []
for one in letters:
	for two in letters:
		if one != two:
			new_letters.append(one + two)
trails = int(input())
cases = []
for trail in range(trails):
	number = input()
	cases.append(number)
for case in cases:
	print(new_letters.index(case) + 1)


def process(wd):
	if wd[1] < wd[0]:
		return (ord(wd[0]) - 97) * 25 + ord(wd[1]) - 96
	elif wd[1] > wd[0]:
		return (ord(wd[0]) - 97) * 25 + ord(wd[1]) - 97
	else:
		return 0
x = int(input())
a = []
for i in range(1, x + 1):
	a.append(process(input()))
for i in range(0, x):
	print(a[i])


allchars = [chr(o) for o in range(97, 97 + 26)]
dictionary = {}
i = 1
for c in allchars:
	for c2 in allchars:
		if c != c2:
			dictionary[c + c2] = i
			i += 1
for _ in range(int(input())):
	print(dictionary[input()])