|시간 제한||메모리 제한||제출||정답||맞은 사람||정답 비율|
|5 초||512 MB||0||0||0||0.000%|
Misaka likes to shoot coins as a powerful railgun.
She prepares a line of coins to fight crime. To produce a stronger coin, she mixes coins together. However, coins with different materials are not compatible to each other, so she only mixes coins with same material together.
Here’s the steps Misaka makes coins:
She repeatedly do these steps until she can’t produce new coins anymore.
Misaka wants to know how many coins she will have. Please help her count coins rapidly!
On the first line there is a single integer T indicating the number of test cases.
The first line of each test case contains an integer N indicating the number of groups of consecutive coins Misaka has. All coins are in a single line.
Then N lines follow, each line containing a character ci and an integer ni, denoting that there are ni consecutive coins with material ci for i-th group of consecutive coins, behind (i − 1)-th.
You may assume:
For each test case, output an integer in one line, indicating the number of coins after Misaka doing the steps of making coins as many as possible.
2 3 A 3 B 1 A 2 3 A 2 B 3 A 2