CF920B.Tea Queue

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Recently nn students from city S moved to city P to attend a programming camp.

They moved there by train. In the evening, all students in the train decided that they want to drink some tea. Of course, no two people can use the same teapot simultaneously, so the students had to form a queue to get their tea.

ii -th student comes to the end of the queue at the beginning of lil_{i} -th second. If there are multiple students coming to the queue in the same moment, then the student with greater index comes after the student with lesser index. Students in the queue behave as follows: if there is nobody in the queue before the student, then he uses the teapot for exactly one second and leaves the queue with his tea; otherwise the student waits for the people before him to get their tea. If at the beginning of rir_{i} -th second student ii still cannot get his tea (there is someone before him in the queue), then he leaves the queue without getting any tea.

For each student determine the second he will use the teapot and get his tea (if he actually gets it).

输入格式

The first line contains one integer tt — the number of test cases to solve ( 1<=t<=10001<=t<=1000 ).

Then tt test cases follow. The first line of each test case contains one integer nn ( 1<=n<=10001<=n<=1000 ) — the number of students.

Then nn lines follow. Each line contains two integer lil_{i} , rir_{i} ( 1<=li<=ri<=50001<=l_{i}<=r_{i}<=5000 ) — the second ii -th student comes to the end of the queue, and the second he leaves the queue if he still cannot get his tea.

It is guaranteed that for every condition li1<=lil_{i-1}<=l_{i} holds.

The sum of nn over all test cases doesn't exceed 10001000 .

Note that in hacks you have to set t=1t=1 .

输出格式

For each test case print nn integers. ii -th of them must be equal to the second when ii -th student gets his tea, or 00 if he leaves without tea.

输入输出样例

  • 输入#1

    2
    2
    1 3
    1 4
    3
    1 5
    1 1
    2 3
    

    输出#1

    1 2 
    1 0 2 
    

说明/提示

The example contains 22 tests:

  1. During 11 -st second, students 11 and 22 come to the queue, and student 11 gets his tea. Student 22 gets his tea during 22 -nd second.
  2. During 11 -st second, students 11 and 22 come to the queue, student 11 gets his tea, and student 22 leaves without tea. During 22 -nd second, student 33 comes and gets his tea.
首页