#codefestival2015qualBd. [codefestival_2015_qualB_d]Squares, Pieces and Coloring

[codefestival_2015_qualB_d]Squares, Pieces and Coloring

Problem Statement

1010010^{100} squares are arranged in a row. The squares are numbered 11 through 1010010^{100} from left to right.

We have NN pieces numbered 11 through N,N, and a counter that can store an integer between 00 and 10100,10^{100}, inclusive.

We will perform NN processes using these tools. Initially, the squares are painted white. The ith(1iN)i^{th} (1≦i≦N) process is as follows:

  1. Place piece ii on square SiS_i, and set the counter to 00.
  2. Look at the color of the square where piece ii is placed. If the square is white, paint it black and increment the counter by 11. Otherwise (if the square is black), move piece ii one square right. As a result, a square may contain multiple pieces.
  3. Terminate the process if the value of the counter is Ci.C_i. Otherwise, go back to step 2.2.

Find the final position of each of the NN pieces after all the NN processes.


Input

Input is given from Standard Input in the following format:

NN S1S_1 C1C_1 S2S_2 C2C_2 : SNS_N CNC_N

  • The first line contains an integer N(1N105).N (1 ≦ N ≦ 10^5).
  • The following NN lines describe the processes. The ith(1iN)i^{th} (1 ≦ i ≦ N) of them contains two space-separated integers Si(1Si109)S_i (1 ≦ S_i ≦ 10^9) and Ci(1Ci109),C_i (1≦C_i≦10^9), denoting the initial position of piece ii in the ithi^{th} process and the termination condition of the ithi^{th} process, respectively.

Partial Points

Partial points may be awarded in this problem:

  • 3535 points will be awarded for passing the test set satisfying the following: The number of the square where each piece is located after all the processes does not exceed 10510^5.
  • Another 4040 points will be awarded for passing the test set satisfying N1000.N ≦ 1000.
  • Another 2525 points will be awarded for passing the test set without additional constraints.

Output

Print NN lines, the ith(1iN)i^{th} (1≦i≦N) of which should contain the number of the square where the piece ii is located after all the NN processes. Be sure to print a newline at the end of output.


Sample Input 1


4
3 3
10 1
4 2
2 4

Sample Output 1


5
10
7
11

Illustrated below is the state of the squares and the pieces after each process:

figure1


Sample Input 2


8
2 1
3 1
1 1
5 1
1 1
9 1
8 2
7 9

Sample Output 2


2
3
1
5
4
9
10
18

Sample Input 3


5
1000000000 1000000000
1000000000 1000000000
1000000000 1000000000
1000000000 1000000000
1000000000 1000000000

Sample Output 3


1999999999
2999999999
3999999999
4999999999
5999999999

Beware that the correct output may not fit into a 3232-bit integer.