Under construction

Still being built. Things may change

Scheduling

Interview

Time limit3sMemory limit2048 MB

Summary
Given n meetings with time windows, find integer start times so each one-hour meeting has at least one hour free before and after, or report -1 if impossible.
Level

Medium5 of 10

Topics
Greedy, Heap, Sorting
Solved
No attempts yet

Problem

Your boss asked you to find a valid schedule for his meetings. He has nn meetings, and the ii-th meeting must start and end within the time interval [ℓi,ri][\ell_i, r_i], where time is measured in hours. Each meeting takes exactly one hour, and your boss cannot attend two meetings at the same time.

As a competitive programmer, you have solved this classic scheduling problem countless times, and only now do you notice that it is unrealistic. How can one person attend over a hundred thousand meetings in different places, with no travel time between them and no breaks at all? Meetings do not always last exactly one hour, and many start late because someone is running late.

These deep philosophical questions may be a big problem for humanity, but since you do not have to attend these meetings yourself, you do not care enough to solve all of them. Impressing your boss is worth it, though, so you try to improve the schedule at least a little.

Find any schedule where there is at least one hour between every pair of meetings, or report that there is none. This is just one small change to the classic problem, right?

Input

Each test contains multiple test cases. The first line contains a single integer tt (1≤t≤1051 \leq t \leq 10^5), the number of test cases. The description of each test case follows.

The first line of each test case contains one integer nn (1≤n≤2⋅1051 \leq n \leq 2 \cdot 10^5), the number of meetings. The next nn lines each contain two integers ℓi\ell_i and rir_i (1≤ℓi<ri≤1061 \leq \ell_i < r_i \leq 10^6), the time interval of the ii-th meeting.

The sum of nn over all test cases does not exceed 2⋅1052 \cdot 10^5.

Output

If there is no valid schedule, output −1-1 on a single line. Otherwise, output nn integers aia_i on a single line, where aia_i is the start time of the ii-th meeting.

Hint

In the first test case, the first meeting starts at the start of hour 11 and lasts one hour, until the start of hour 22. After that, your boss takes a one-hour break before the third meeting, which runs from the start of hour 33 to 44. Then he takes another one-hour break before the second meeting, which runs from the start of hour 55 to 66.

Note that it is not possible to start the third meeting at the start of hour 44, because that meeting would end at 55.

Examples1

  1. Example 1

    Input
    4
    3
    1 3
    1 7
    2 4
    2
    1 2
    2 3
    4
    1 5
    2 6
    3 4
    4 7
    2
    1 5
    2 3
    
    Expected output
    1 5 3
    -1
    -1
    4 2