Scheduling
InterviewTime limit3sMemory limit2048 MB
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.
Problem
Your boss asked you to find a valid schedule for his meetings. He has meetings, and the -th meeting must start and end within the time interval , 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 (), the number of test cases. The description of each test case follows.
The first line of each test case contains one integer (), the number of meetings. The next lines each contain two integers and (), the time interval of the -th meeting.
The sum of over all test cases does not exceed .
Output
If there is no valid schedule, output on a single line. Otherwise, output integers on a single line, where is the start time of the -th meeting.
Hint
In the first test case, the first meeting starts at the start of hour and lasts one hour, until the start of hour . After that, your boss takes a one-hour break before the third meeting, which runs from the start of hour to . Then he takes another one-hour break before the second meeting, which runs from the start of hour to .
Note that it is not possible to start the third meeting at the start of hour , because that meeting would end at .