#K55272. Correcting Misplaced Categories by Weight

    ID: 29939 Type: Default 1000ms 256MiB

Correcting Misplaced Categories by Weight

Correcting Misplaced Categories by Weight

You are given a number of test cases. In each test case, you are provided with a list of items and a list of correct category ranges based on weight. Each item is recorded with a weight and an incorrect category. For each item, assign the correct category if the weight falls within the weight range of that category. The weight criteria is given by the inequality \(min\_weight \leq weight \leq max\_weight\).

Input Format:

  • The first line contains an integer \(T\), the number of test cases.
  • For each test case:
    • The first line contains an integer \(N\), the number of items.
    • The next \(N\) lines each contain an integer and a string separated by space representing the weight and the recorded category.
    • The next line contains an integer \(M\), the number of correct category ranges.
    • The next \(M\) lines each contain a string and two integers separated by spaces representing the category, minimum weight, and maximum weight, respectively.

Output Format:

  • For each test case, output \(N\) lines. Each line should contain the weight and the corrected category (separated by a space) for the corresponding item, in the same order as input.

Note: It is guaranteed that each item will match exactly one correct category range.

inputFormat

The input is read from standard input (stdin) and is structured as follows:

T
N
weight1 recorded_category1
weight2 recorded_category2
... (N items)
M
category1 min1 max1
category2 min2 max2
... (M ranges)
... (repeated for each test case)

outputFormat

For each test case, output N lines to standard output (stdout). Each line should contain the weight and the correct category (separated by a space) for that item. If there are multiple test cases, the outputs are printed sequentially.

## sample
1
5
5 A
10 B
20 A
35 C
50 B
3
A 1 20
B 21 45
C 46 60
5 A

10 A 20 A 35 B 50 C

</p>