KZWC - Z meet

The Z-meet is an annual alumni meet of the department of Computer Science at PSG college of technology, where students of different batches meet. The batch names are named in a alphabetical order and ending with Z (hence the name Z-meet). That is Aztecz, Byzandierz, Calitz, Dextroblitz, Espritz, F5erz and Griffinxeritz. The event is held in a hall and the students are seated in random order. The event co-ordinators have a problem. They need to find the strength of attendance of the event by different batches which is calculated as follows:

  1. Each person in the hall shouts out a number which is calculated as (year of Z-meet - year of pass-out )2 if he is a alumni or (year of Z-meet - year of entering)2 if he is still a student. Assume the batch of the year in which Z-meet is not passed out.
  2. The numbers shouted by each person in the hall is added to get the strength of attendance. The year of passing and year of entering of the different batches are given.
    Aztecz        2001-2005
    Byzandiarz    2002-2006
    Calitz        2003-2007
    Dextroblitz   2004-2008
    Espritz       2005-2009
    F5erz         2006-2010
    Griffinxeritz 2007-2011 

For example if the event is held in 2008 the Aztecz batch member shouts (2008-2005)2 = 9, and a Dextroblitz member shouts (2008-2004)2 = 16

Help the event co-ordinator by writing a program to find strength of attendance.

Input

There is a single positive integer T on the first line indicating the number of test cases to follow. Then there are T lines each containing a year in which Z-meet is held and a string giving the seating arrangement of the alumni and students. That is A refers to Aztecz member C refers to Calitz member and so on.

Output

For every string, output a single line containing the strength of attendance of the event.

Example

Input:
3
2008 ADECBA
2006 BABACAD
2009 BEGFADEG

Output:
48
48
75

Added by:balaji
Date:2009-09-19
Time limit:0.100s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:ADA95 DOC ASM32 BASH BF C CSHARP CPP C99 CLPS LISP sbcl LISP clisp D FORTRAN HASK ICON ICK JAVA LUA NEM NICE OCAML PAS-GPC PAS-FPC PDF PERL PHP PIKE PS PRLG-swi PYTHON RUBY SCALA SCM guile SCM qobi ST TCL TEXT WHITESPACE
Resource:kruzade 09 practice

hide comments
2010-05-10 15:22:54 Maciej Grzymkowski
erm, how do we recognize whether 'A' means a student or an alumni?
2009-09-24 19:05:12 pankaj
these questions should be in tutorial section.

Re: I'll consider your suggestion.(Edit by Blue Mary.)

Last edit: 2009-09-25 05:46:00
2009-09-21 09:55:06 Ajay Nair
I thoroughly agree "Reading the problem is harder than actually coding it"
2009-09-20 20:36:31 JaceTheMindSculptor
what the heck? A guy with 0.2 points and 5 solved questions can become a problem setter?
2009-09-20 18:58:36 Nicholas James
yes please fix the formatting of the test data.
when i used scanf() and getchar() to read the input i was getting WA. but when I changed to cin (which isn't effected by extra spaces and new line) i got AC.
2009-09-20 14:06:17 Jelle van den Hooff
Please, format your problem correctly. There are missing spaces, extra line breaks and missing capitals. Reading the problem is harder than actually coding it.
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.