#K4521. Maximizing Card Pile Sum

    ID: 27703 Type: Default 1000ms 256MiB

Maximizing Card Pile Sum

Maximizing Card Pile Sum

You are given one or more decks of playing cards. Each deck consists of several cards, and each card has a suit and an integer value. The suit is one of 'H', 'D', 'C', or 'S'. Your task is to determine the maximum possible total sum of card values by dividing each deck into two piles. Although the rule states that you must split the cards into two piles, note that any partition of the suits will always yield a total sum equal to the sum of all card values.

For example, consider a deck with cards: [('H', 3), ('D', 5), ('C', 4), ('S', 2), ('H', 7)]. The sum is

sum=3+5+4+2+7=21\text{sum} = 3 + 5 + 4 + 2 + 7 = 21

You are required to output the maximum possible sum for each deck, which in this case is the total sum of the card values.

inputFormat

The input is given via stdin and has the following format:

The first line contains an integer T, representing the number of decks. For each deck, the first line contains an integer k, indicating the number of cards in the deck. This is followed by k lines, each containing a suit (one of 'H', 'D', 'C', 'S') and an integer value, separated by a space.

outputFormat

For each deck, output a single line containing the maximum possible sum of the card values.## sample

2
5
H 3
D 5
C 4
S 2
H 7
4
D 1
C 3
S 8
C 5
21

17

</p>