Administrative Difficulties#6417

Administrative Difficulties

1 second
128 megabytes
Easy
prb6417

It is difficult for a spy to do his job without a decent car. The Bureau of Administrative Personnel for Cars (BAPC) spy-car rental company has a large collection of cars that spies can use and handles the resulting administration. Using cars obviously costs money: they require gasoline to operate and repairs are needed quite often, because spies tend to cause accidents a little more often than other drivers.

At the end of the year, all spies need to be billed for the cars they used in the past year. Last week, there was a major crash in the billing system, rendering it unusable. All that could be recovered was a list of all available car types and a log of events for the past year. Using this information, the spy-car rental company wants to obtain a list of the car usage costs for every spy on record. This list can then be used to send out the bills manually.

Every type of car is registered with a catalog price, a pick-up cost, and a cost per kilometer driven. The event log contains three types of events: pick-ups, returns, and accidents. When a spy picks up a car, they must pay the pick-up cost for that car. Once the car is returned, the number of kilometers driven with the car is recorded and the spy must pay for them. If an accident occurred while the spy had the car, repairs need to be paid for. Every accident has a severity as a percentage. To repair the car, this percentage of the catalog price is billed to the spy who caused the accident. If any billed cost is fractional, it is rounded up before being added to the bill.

The list of all available types of cars is complete. However, because of the crash, some events in the recovered log might be missing. The company does not want to present spies with an inconsistent bill, so you should detect inconsistencies in the log entries for each spy. The following conditions hold for a consistent event log:

Input

The first line contains a positive integer: the number of test cases, at most 100. Each test case consists of:

  • One line with two space-separated integers and (0 \leq n \leq 500, 0 \leq m \leq 10000): the number of car types and the number of events, respectively.

  • lines, each with a string and three integers , and (1 \leq p \leq 100000, 1 \leq q \leq 1000, 1 \leq k \leq 100), all separated by a space: for each type of car, its unique name, its catalog price, its pick-up cost, and its cost per kilometer.

  • lines, each starting with an integer (0 \leq t \leq 100000), a string and a character , all separated by a space: the time of the event, the spy's name, and the type of event, followed by:

    • if = 'p' (pick-up): a string : the name of the car picked up

    • if = 'r' (return): an integer (0 \leq d \leq 1000): the distance driven by this spy since last pick-up, in kilometers

    • if = 'a' (accident): an integer (0 \leq s \leq 100): the severity of the accident, as a percent

All spies' names and car names contain at least and at most lowercase letters. There are at most unique spy names in each test case. Events are given in chronological order.

Output

For each test case, output one line per spy referenced in any event, containing the spy's name and their total car usage cost, separated by a space. If the event log for the spy is inconsistent, replace the total cost with the string INCONSISTENT.

The output lines must be sorted alphabetically by spy name.

Examples

Example 1

Loading
Loading