HST

Time limit1sMemory limit128 MB

Summary
Given tax rate categories and monthly purchases, compute the difference between total HST paid and total PST plus GST paid, with each tax rounded per item.
Level

Medium6 of 10

Topics
Math, Implementation, Simulation, Hash map
Solved
No attempts yet

Problem

On July 1st, Ontario's Provincial Sales Tax (PST) was merged with the Federal Goods and Services Tax (GST) to create the Harmonized Sales Tax (HST). This changed the rate of tax that Ontarians pay on various items.

Dalton would like to calculate how this change will affect his personal monthly budget.

Input

The first line of input contains a single integer: the number of test cases that follow.

Each test case begins with a line containing two integers NN and MM — the number of categories of items and the number of purchases Dalton makes each month. Each of NN and MM is between 1 and 100000, inclusive.

The next NN lines each describe a category. A category line contains a category name — a string of at most 30 letters — followed by three percentages giving the PST, GST, and HST rate for that category. Each percentage has up to two digits after the decimal point and is written with a trailing % symbol; every percentage is at least 0% and at most 100%.

The following MM lines each describe one of Dalton's purchases. A purchase line contains a category name followed by a price in dollars and cents prefixed by a \$ sign; this is the pre-tax amount Dalton spends on an item in that category.

The amount of each tax on an item is rounded to the nearest cent; if the tax amount is exactly half a cent above a whole number of cents, it is rounded up to the next whole cent.

Output

For each test case, output on its own line the difference, in dollars and cents (two digits after the decimal point), between the total HST payable and the total PST plus GST payable on Dalton's monthly purchases. Output a positive amount if the HST exceeds the PST plus GST, and a negative amount (prefixed with -) if the HST is less.

Examples3

  1. Example 1

    Input
    1
    1 1
    gas 0% 5% 13%
    gas $100.00
    
    Expected output
    8.00
    
  2. Example 2

    Input
    1
    1 1
    clothes 10% 5% 5%
    clothes $100.00
    
    Expected output
    -10.00
    
  3. Example 3

    Input
    1
    1 2
    candy 0% 0% 5%
    candy $0.10
    candy $0.10
    
    Expected output
    0.02