Scheduling
시간 제한3초메모리 제한2048 MB
각 회의를 주어진 구간 안의 한 시간 슬롯에 배정하되, 어떤 두 회의 사이에도 최소 한 시간의 공백이 생기도록 하고, 불가능하면 -1을 출력한다.
문제
Your boss made you find a valid schedule for his meetings. He has meetings, where the -th meeting has to start and end in the time interval , where time is measured in hours. Each meeting takes exactly one hour, and your boss obviously cannot attend two meetings at the same time.
As a competitive programmer, you have already solved this classical scheduling problem countless times, and this time, you finally notice that it is completely unrealistic. How can one person attend over a hundred thousand meetings at different places without any time to travel between them and without taking any breaks either? There is no way every meeting takes exactly one hour -- speaking from experience -- and there will surely be meetings that start late because someone is running late.
These deep-rooted philosophical questions may be a big problem for humanity, but since you do not have to attend these meetings yourself, you simply do not care enough to solve all of them. However, impressing your boss will certainly be worth it for you, so you try to at least improve the schedule a little bit.
Find any schedule where there is at least one hour between every pair of meetings or report that there is none. Surely this is just one insignificant change to the classical problem, right?
입력
Each test contains multiple test cases. The first line of input contains a single integer () --- the number of test cases. The description of the test cases 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 in hours the -th meeting has to start and end in.
The sum of over all test cases does not exceed .
출력
If there is no valid schedule, output in a single line. Otherwise, output integers in a single line where is the start time of the -th meeting.
힌트
In the first test case, the first meeting starts at the start of hour and goes on for one hour until the start of hour . After that, your boss takes a break of one hour until he attends the third meeting from the start of hour to . Then, he takes another one hour break until he finally attends the second meeting, which happens from the start of hour to .
Note that it is not possible to start the third meeting at the start of hour as this meeting would end at .