0 Judge
Code: 0
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 $c_i$ and an integer $n_i$, denoting that there are $n_i$ consecutive coins with material $c_i$ 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
2
3
御坂喜歡用硬幣當作電磁炮射擊。
為了打擊犯罪,她準備了一排硬幣。為了生產出更強力的硬幣,她會把硬幣們混合在一起。然而,不同材質的硬幣之間並不相容,所以她只會將相同材質的硬幣混合。
以下是御坂製作硬幣的步驟:
她會重複做這些步驟,直到她不能再生產新的硬幣。
御坂想要知道她最後會有多少硬幣。請趕快幫她計算硬幣吧!
第一行有一個整數 $T$ ,表示測試資料的數量。
每組測試資料的第一行有一個正整數 $N$,表示御坂有 $N$ 組連續的硬幣。所有硬幣都在一排之中。
接著有 $N$ 行,每一行有一個字元 $c_i$ 和正整數 $n_i$ ,表示第 $i$ 組有連續 $n_i$ 個材質為 $c_i$ 的硬幣,接在第 $(i-1)$ 組硬幣之後。
可假設:
對於每組測試資料,輸出一個整數於一行,表示御坂在做完盡量多次製作硬幣的步驟之後,有多少硬幣。