#AGC013C. [AGC013C] Ants on a Circle

[AGC013C] Ants on a Circle

Score : 700700 points

Problem Statement

There is a circle with a circumference of LL. Each point on the circumference has a coordinate value, which represents the arc length from a certain reference point clockwise to the point. On this circumference, there are NN ants. These ants are numbered 11 through NN in order of increasing coordinate, and ant ii is at coordinate XiX_i.

The NN ants have just started walking. For each ant ii, you are given the initial direction WiW_i. Ant ii is initially walking clockwise if WiW_i is 11; counterclockwise if WiW_i is 22. Every ant walks at a constant speed of 11 per second. Sometimes, two ants bump into each other. Each of these two ants will then turn around and start walking in the opposite direction.

For each ant, find its position after TT seconds.

Constraints

  • All input values are integers.
  • 1N1051 \leq N \leq 10^5
  • 1L1091 \leq L \leq 10^9
  • 1T1091 \leq T \leq 10^9
  • 0X1<X2<...<XNL10 \leq X_1 < X_2 < ... < X_N \leq L - 1
  • 1Wi21 \leq W_i \leq 2

Input

The input is given from Standard Input in the following format:

NN LL TT

X1X_1 W1W_1

X2X_2 W2W_2

::

XNX_N WNW_N

Output

Print NN lines. The ii-th line should contain the coordinate of ant ii after TT seconds. Here, each coordinate must be between 00 and L1L-1, inclusive.

3 8 3
0 1
3 2
6 1
1
3
0

1.51.5 seconds after the ants start walking, ant 11 and 22 bump into each other at coordinate 1.51.5. 11 second after that, ant 11 and 33 bump into each other at coordinate 0.50.5. 0.50.5 seconds after that, that is, 33 seconds after the ants start walking, ants 11, 22 and 33 are at coordinates 11, 33 and 00, respectively.

4 20 9
7 2
9 1
12 1
18 1
7
18
18
1