#C5413. Final Shelf Configuration
Final Shelf Configuration
Final Shelf Configuration
You are given several shelves, each containing a list of integers. You will perform a sequence of removal operations on these shelves. Each removal operation is described by two 1-indexed integers \(i\) and \(j\), meaning that you must remove the \(j\)th element from the \(i\)th shelf.
The removals are performed sequentially in the order they are given. Note that after a removal operation, the indices of the remaining elements on that shelf will shift. Your task is to determine the final configuration of the shelves after all removals have been made.
For example, if a shelf initially contains [4, 5, 6] and the removal operation (1,2) is applied (i.e. remove the second element on the shelf), the shelf will become [4, 6].
inputFormat
The input is read from standard input and has the following format:
T N k1 a11 a12 ... a1k1 k2 a21 a22 ... a2k2 ... kN aN1 aN2 ... aNkN R i1 j1 i2 j2 ... iR jR ... (repeated for each test case)
Here, T is the number of test cases. For each test case,
- N is the number of shelves.
- Each of the next N lines starts with an integer k (the number of items on that shelf) followed by k integers representing the items on that shelf.
- R is the number of removal operations.
- Each of the next R lines contains two integers \(i\) and \(j\) indicating that from the \(i\)th shelf, the \(j\)th item should be removed.
All indices are 1-indexed.
outputFormat
For each test case, output the final configuration of the shelves. For each shelf, print a line containing its remaining elements separated by a single space. If a shelf is empty, output an empty line. The outputs for different test cases are concatenated one after another.
## sample3
3
1 1
2 2 3
3 4 5 6
2
1 1
3 2
3
1 1
3 2 3 4
4 5 6 7 8
4
2 1
2 2
1 1
3 3
3
1 1
2 2 3
3 4 5 6
0
2 3
4 6
3
5 6 8
1
2 3
4 5 6
</p>