#C1243. Vending Machine Earnings

    ID: 41856 Type: Default 1000ms 256MiB

Vending Machine Earnings

Vending Machine Earnings

You are given a vending machine that sells various snacks. Each snack has a unique name and a fixed price. You are provided with T test cases. For each test case, you will first be given an integer n representing the number of available snacks. The next n lines each contain a snack name and its price. Then, an integer m is given representing the number of purchases made, followed by m lines each containing the name of a purchased snack.

Your task is to compute the total earnings for each test case. Mathematically, for a given test case, if a snack s has price p_s and is purchased k_s times, then the total earnings for that test case is given by:

\( Earnings = \sum_{s \in \text{snacks}} k_s \times p_s \)

Output the total earnings for each test case on a separate line.

inputFormat

The input begins with an integer T denoting the number of test cases. For each test case:

  • An integer n representing the number of available snacks.
  • n lines follow, each containing a snack name (a string) and its price (an integer) separated by a space.
  • An integer m representing the number of purchases.
  • m lines follow, each containing the name of a purchased snack.

All inputs are read from standard input (stdin).

outputFormat

For each test case, output a single line containing the total earnings. The outputs should be in the same order as the test cases in the input, printed to standard output (stdout).

## sample
2
3
Chips 50
Soda 30
Candy 20
5
Chips
Soda
Candy
Chips
Soda
2
Water 10
Juice 40
3
Water
Juice
Water
180

60

</p>