The World Chess Championship
is about to start. Classical games will be played between Chef and Carlsen in the championship, where each game has one of three outcomes — it can be won by Carlsen, won by Chef, or it can be a draw. The winner of a game gets points, and the loser gets points. If it’s a draw, both players get point each.
The total prize pool of the championship is . At end of the Classical games, if one player has strictly more points than the other, he is declared the champion and gets as his prize money, and the loser gets .
If the total points are tied, then the defending champion Carlsen is declared the winner. However, if this happens, the winner gets only , and the loser gets .
Given the results of all the games, output the prize money that Carlsen receives.
The results are given as a string of length consisting of the characters C
, N
, and D
.
C
denotes a victory by Carlsen.N
denotes a victory by Chef.D
denotes a draw.
Input Format
- The first line of input contains an integer , denoting the number of test cases. The description of test cases follows.
- The first line of each test case contains one integer , denoting that the total prize pool is .
- The second line contains the results of the match, as a string of length containing only the characters
C
,N
, andD
.
Output Format
For each test case, output in a single line the total prize money won by Carlsen.
Constraints
- contains only characters
D
,C
,N
.
Subtasks
Subtask #1 (100 points): Original constraints
Sample Input 1
4
100
CCCCCCCCCCCCCC
400
CDCDCDCDCDCDCD
30
DDCCNNDDDCCNND
1
NNDNNDDDNNDNDN
Sample Output 1
6000
24000
1650
40
Explanation
Test case : Since Carlsen won all the games, he will be crowned the champion and will get as the prize money which is
Test case : Carlsen won games and drew , so his score is . Chef lost games and drew , so his score is . Since Carlsen has more points, he will be crowned the champion and will get as the prize money which is
Test case : Carlsen and Chef both end up with points. So, Carlsen is declared the winner, but because the points were tied, he receives in prize money.
ConversionConversion EmoticonEmoticon