#K82002. Warehouse Goods Transfer Report

    ID: 35878 Type: Default 1000ms 256MiB

Warehouse Goods Transfer Report

Warehouse Goods Transfer Report

In this problem, you are required to process a set of goods transfer requests between warehouses located in two cities: Alpha and Beta. Each request is characterized by a starting city, a destination city, the respective warehouse numbers, the quantity of goods, a priority, and an order indicating the sequence in which requests were received. You must process the requests in increasing order of their priorities; when two requests share the same priority, process the one that appears earlier in the input. After executing all transfers, compute the net balance of goods for each warehouse. The final report should list the net balances of all warehouses in Alpha followed by those in Beta.

The transfer process follows these rules:

  1. If a request originates from city Alpha, subtract the number of goods from the specified warehouse in Alpha and add that number to the designated warehouse in Beta.
  2. If a request originates from city Beta, subtract the number of goods from the specified warehouse in Beta and add that number to the designated warehouse in Alpha.

The final output for each test case should be the concatenation of the balances of warehouses in Alpha and Beta, in that order.

inputFormat

Input is given via standard input (stdin). The first line contains an integer T, representing the number of test cases. For each test case, the first line contains three integers: N, M, Q. N is the number of warehouses in city Alpha, M is the number of warehouses in city Beta, and Q is the number of transfer requests. Each of the following Q lines contains a transfer request in the following format:

<src_city> <src_warehouse> <dest_city> <dest_warehouse> <number_of_goods> <priority>

Here, <src_city> and <dest_city> are either 'A' or 'B' (representing Alpha and Beta, respectively). The order of the requests in the input determines their arrival order.

outputFormat

For each test case, output a single line to standard output (stdout) containing N+M space-separated integers. The first N integers represent the net balance (goods added minus goods removed) for warehouses in Alpha, and the next M integers represent the net balance for warehouses in Beta.## sample

1
3 2 4
A 1 B 1 20 1
B 2 A 3 30 2
A 2 B 2 50 1
A 3 B 1 10 3
-20 -50 20 30 20