GPACALC - Calculate your GPA

Design a calculator to calculate your GPA. Possible grades are S, A, B, C, D and E. S corresponds to 10 credits, A to 9, B to 8, C to 7, D to 6 and E to 5. There are n subjects. Each subject has a number of credits and the grade obtained by the student.

GPA of the student is the summation of [[grades obtained multiplied by the number of credits for each subject]] divided by the total number of credits. For example, if input is n = 3 and three subjects have credits 3, 4 and 5. A student has obtained grade S, A and B respectively, then GPA = (3*10 + 4*9 + 5*8)/(3+4+5)

Input

First line consists of t, the number of test cases (1 <= t <= 20). Each test case starts with n, the number of subjects (1 <= n <= 16). The next n lines consist of credits for that subject followed by grade obtained by the student (1 <= credits <= 10 and grade will be one among S, A, B, C, D and E)

Output

For each test case, print the GPA of the student rounded off to two decimal places.

Example

Input:
1
12
4 D
1 E
1 S
3 D
1 E
2 A
4 A
4 A
3 C
1 C
1 B
2 D

Output:
7.41

Added by:Pandian
Date:2013-12-19
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All
Resource:Own

hide comments
2013-12-21 20:24:10 Prashant Kiran
Anyone what is th eoutput format


Last edit: 2013-12-21 20:26:48
2013-12-21 20:17:38 akulsareen
what are the standard rounding off rules?
2013-12-21 20:17:28 Bhavik
what does rounding off means here??
truncated result or what??
2013-12-21 20:03:20 Prashant Kiran
Works on my pc but gives WA after running(2)...please check input output...and do we have to print output just after evry test case or all at once?
2013-12-21 19:59:03 Jayant Dalmia
There has to be some mistake in the question details.
2013-12-21 19:31:19 suryadev
pls do the rounding off in double carefully!
2013-12-21 19:08:55 Nick
yes, it's correct

Last edit: 2013-12-21 19:09:04
2013-12-21 18:44:51 Sushant Gupta
provide some more test cases... giving correct results for me but showing wrong answer
2013-12-21 18:19:15 Pandian
@udhayakumar : Nope. The question and ip, op is correct.

Last edit: 2013-12-21 18:28:14
2013-12-21 17:35:48 S.Udhayakumar
No body got the answer correct for such a simple question.Something wrng with this question.Please check the ip and output.My solution works localy fails in spoj server.
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.