Stump Speech

No attempts yetTime limit1sMemory limit128 MB

Problem

In the past a candidate would simply tell voters what they thought and what they were going to do (perhaps stretching the truth a little — even the good old days were not really that good). Nowadays every statement and speech is carefully prepared and focus-group tested to make sure it does not trigger any negative reaction or create any unwanted association. Focus groups literally sit down with levers in their hands and, while listening to the speech, use a lever to trace how positively they feel about the candidate. Based on that feedback the speech is then rewritten.

Wouldn't it be much easier to skip the real focus group and instead have a computer program tell us how people would react to a speech? Here we write a first, rough approximation of such a tool. You are given a list of key words and phrases together with the reactions they trigger, and from these you assess the quality of the speech.

More precisely, each phrase has a positive or negative score. For example, taxes might score -2, increase taxes -4, education 3, and slash education -6. You count how many times each phrase occurs in the speech and add up the matching scores to obtain the total score of the speech.

Input

The first line contains an integer $K$ ($K \geq 1$), the number of data sets. It is followed by $K$ data sets of the following form.

The first line of a data set contains an integer $n$, the number of scored words or phrases.

This is followed by $n$ pairs of lines. The first line of each pair is a key phrase of at most 80 characters, consisting only of lower-case letters and white space. The second line is the phrase's score, a positive or negative integer.

After the $n$ pairs comes one more line, of at most 10000 characters, containing the candidate's speech. This line consists only of lower-case letters, white space, and the punctuation marks . and ,. The speech is always given on a single line and never contains a line break.

Output

For each data set, first output a line Data Set x:, where x is the number of the data set (the first data set is number 1). On the next line output the total score of the speech.

The total score is the sum, over all key phrases, of the phrase's score multiplied by the number of times the phrase occurs in the speech (a phrase that occurs several times is counted several times). Different phrases are counted independently, so a shorter phrase is still counted when it appears inside a longer one. A phrase is matched as an exact substring of the speech: if even the amount of white space differs, it is not treated as the phrase.