Rental car management trouble

No attempts yetTime limit2sMemory limit128 MB

Problem

A suitable car is a necessity for a spy. A rental company called BAPC keeps a wide selection of cars that suit a spy, and it also takes care of everything that happens after a car comes back. Looking after a car that a spy returns costs money. The tank has to be refilled, and in most cases the wrecked car has to be repaired.

At the end of each year, every spy who used the company pays for the cars driven that year. Last week the management system broke badly and can no longer be used. All that was salvaged is the car information and part of last year's event log. The company wants to work out each spy's bill by hand from what is left.

Every car is registered with its price, an initial rental fee, and an extra charge for each kilometer driven. An event record is a pick-up, a return, or an accident. A spy who picks up a car pays that car's initial rental fee. On returning it, the spy pays the extra charge in proportion to the distance driven up to the moment of return. If the car was wrecked in an accident during the rental, the repair is billed as well. Every accident record stores the damage rate of the car, and the repair cost is the price of that car multiplied by the damage rate. A cost with a fractional part is rounded up before it is added to the bill.

The list of cars was recovered in full, but the event log stayed broken. Sending spies bills that do not add up would cost the company a lot of trust, so you want to write a program that decides whether the surviving event log is consistent. A consistent log satisfies all of the following.

  • A spy picks up a car before returning one.
  • Every car that is picked up is returned.
  • A spy rents at most one car at a time.
  • An accident happens only while the spy has a car.

Input

The first line contains the number of test cases, which is at most 100.

Each test case is laid out as follows.

  • Two integers nn and mm separated by a space (0n5000 \le n \le 500, 0m100000 \le m \le 10000): the number of car models and the number of lines in the event log
  • nn lines, each holding a string NN and three integers pp, qq, kk separated by spaces (1p1000001 \le p \le 100000, 1q10001 \le q \le 1000, 1k1001 \le k \le 100): the name of the car, its price, the initial rental fee, and the charge added for each kilometer driven
  • mm lines, each starting with an integer tt (0t1000000 \le t \le 100000) for the time of the event, a string SS for the name of the spy involved, and a single letter ee for the kind of event, all separated by spaces, followed by one more value that depends on ee.
  1. If ee is p (pick-up), a string CC: the name of the car that was picked up
  2. If ee is r (return), an integer dd: the distance driven, in kilometers
  3. If ee is a (accident), an integer ss (0s1000 \le s \le 100): the damage rate of the car

Car names and spy names are 1 to 40 lowercase letters long. Each test case has at most 500 spies, and the events are given in the order they happened.

Output

For each test case, sort the spies that appear in the event log by name in lexicographic order and print one per line.

  • Each line holds the name of the spy and the total amount billed, separated by a space.
  • If a spy's event records are not consistent, print INCONSISTENT in place of the total.

Do not print a blank line between test cases.