On a single machine, there are $n$ independent tasks waiting to be scheduled. A task started at time $t$ will finish at time $t+1$. All tasks can only be started at integer times; as soon as one task finishes, another task can be started immediately. While a task is being executed, no other task can be executed.
Tasks are time-sensitive. Specifically, the start time of the $i$-th task must be between time $l_i$ and time $r_i$ (inclusive).
In addition, there are $m$ constraints. The $j$-th constraint states that between time $p_j$ and time $q_j$ (inclusive), at most one task can be started.
Please determine the start time of each task so that all the above requirements are satisfied.
Input
This problem contains multiple test cases.
The first line of the input contains a non-negative integer $T$, denoting the number of test cases.
The test cases follow in order. For each test case:
The first line contains two integers $n$ and $m$.
The next $n$ lines each contain two integers $l_i$ and $r_i$, denoting the available time interval for the $i$-th task.
The next $m$ lines each contain two integers $p_j$ and $q_j$, denoting the $j$-th scheduling constraint interval.
Output
For each test case, output a single line containing $n$ integers, denoting the start time of each task in order. In particular, if no valid schedule exists, output Impossible. If there are multiple valid schedules, you may output any of them.
Sample 1
Input
4 2 3 2 7 1 10 7 8 2 10 1 6 2 2 2 5 1 9 1 5 4 9 2 4 3 8 3 6 2 7 4 7 8 9 1 6 4 1 6 7 6 7 6 7 1 11 21 31
Output
7 1 3 9 8 6 Impossible
Note
This sample satisfies the constraints of Subtask $1$.
- For the first test case, the two tasks start at times $7,1$ respectively. Both are within their respective $[l,r]$ ranges, and all constraints are satisfied.
- For the fourth test case, the first three tasks can only start at time $6$ or $7$. Therefore, no valid schedule exists.
Sample 2
See ex_data2.in and ex_data2.ans in the additional files.
This sample satisfies the constraints of Subtask $2$.
Sample 3
See ex_data3.in and ex_data3.ans in the additional files.
This sample satisfies the constraints of Subtask $3$.
Sample 4
See ex_data4.in and ex_data4.ans in the additional files.
This sample satisfies the constraints of Subtask $4$.
Sample 5
See ex_data5.in and ex_data5.ans in the additional files.
This sample satisfies the constraints of Subtask $5$.
Sample 6
See ex_data6.in and ex_data6.ans in the additional files.
This sample satisfies the constraints of Subtask $6$.
Sample 7
See ex_data7.in and ex_data7.ans in the additional files.
This sample satisfies the constraints of Subtask $7$.
Sample 8
See ex_data8.in and ex_data8.ans in the additional files.
This sample satisfies the constraints of Subtask $8$.
Constraints
Let $N,M$ be the sums of $n,m$ over all test cases in a single test point, respectively. For all test cases:
- $1 \le n \le 2.5 \times 10^5,0 \le m \le 2.5 \times 10^5$;
- $1 \le l_i \le r_i \le 10^{9}$;
- $1 \le p_j \le q_j \le 10^{9}$.
| Subtask | $N\le$ | $M\le$ | Special Property | Score |
|---|---|---|---|---|
| $1$ | $10$ | $10$ | None | $5$ |
| $2$ | $2.5\times 10^5$ | $2.5\times 10^5$ | $\rm A$ | $5$ |
| $3$ | $10^3$ | $10^3$ | $\rm B$ | $15$ |
| $4$ | $2.5\times 10^5$ | $2.5\times 10^5$ | $\rm C$ | $15$ |
| $5$ | $10^4$ | $10^4$ | $\rm B$ | $15$ |
| $6$ | $10^5$ | $10^5$ | $\rm B$ | $15$ |
| $7$ | $10^5$ | $10^5$ | None | $15$ |
| $8$ | $2.5\times 10^5$ | $2.5\times 10^5$ | None | $15$ |
$\rm A$: It is guaranteed that $n\le100$, and for all $1\le i< n$, $l_i\le l_{i+1}$ and $r_i\le r_{i+1}$.
$\rm B$: For all $1\le i\le n$, $r_i\le 5\max(n,m)$.
$\rm C$: For all $1\le i\le m$, $p_i=i,q_i=i+1$, and for all $1\le i\le n$, $r_i\le m$.