Woburn ECOO 1997 at Gramercy

AC-Counting

INPUT FILE: account.in
OUTPUT FILE: account.out

Even though we have decimal, binary, hexadecimal, octal and countless other bases in which to count, people tire of numerical bases and want one with letters.
Consider counting in a new base AC: the first "number" is a and counting from there gives the following sequence:

a, b, c, d, e, ..., y, z, ab, ac, ad, ae, ..., ay, az, bc, bd, ..., bz, cd, ..., wx, wy, wz, xy, xz, yz

Note that each literal has length <= 2, and each letter is strictly larger than the one before it (i.e., aa or zz are NOT allowed). We are interested in knowing the index of a given literal: for example, a has index 1, z 26, ab 27, and so forth. Given any literal from the above sequence (guaranteed to be valid) output its index.

INPUT
The first line will contain an integer n.
On each of the next n lines you will be given a base AC "number."

OUTPUT
Output the index of each "number" on a separate line.

BONUS
Generalize to work with literals of any length (up to 26).

Sample Input File

4
a
ab
az
yz

Output for Sample Input

1
27
51
351
Downloader failed! Response object 006~ASP 0159~Buffering Off~Buffering must be on.