Problem:
Score : 700 points

Problem Statement

There is a circle with a circumference of L.
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 N ants.
These ants are numbered 1 through N in order of increasing coordinate, and ant i is at coordinate X_i.

The N ants have just started walking.
For each ant i, you are given the initial direction W_i. Ant i is initially walking clockwise if W_i is 1; counterclockwise if W_i is 2.
Every ant walks at a constant speed of 1 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 T seconds.

Constraints

All input values are integers.

1 \leq N \leq 10^5

1 \leq L \leq 10^9

1 \leq T \leq 10^9

0 \leq X_1 < X_2 < ... < X_N \leq L - 1

1 \leq W_i \leq 2

Input

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

N L T
X_1 W_1
X_2 W_2
:
X_N W_N

Output

Print N lines.
The i-th line should contain the coordinate of ant i after T seconds. Here, each coordinate must be between 0 and L-1, inclusive.

Sample Input 1

3 8 3
0 1
3 2
6 1

Sample Output 1

1
3
0

1.5 seconds after the ants start walking, ant 1 and 2 bump into each other at coordinate 1.5.
1 second after that, ant 1 and 3 bump into each other at coordinate 0.5.
0.5 seconds after that, that is, 3 seconds after the ants start walking, ants 1, 2 and 3 are at coordinates 1, 3 and 0, respectively.

Sample Input 2

4 20 9
7 2
9 1
12 1
18 1

Sample Output 2

7
18
18
1

Solution in C++14 (GCC 5.4.1) (judge verdict: Accepted)

#ifdef __APPLE__
#include <cassert>
#include <iostream>
#include <iomanip>
#include <ctime>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <stack>
#include <string>
#include <cstring>
#include <sstream>
#include <map>
#include <set>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <cctype>
#include <list>
#include <cmath>
#include <limits>
#include <bitset>
#include <numeric>
#include <climits>
#include <complex>
#else
#include<bits/stdc++.h>
#endif // __APPLE__
using namespace std;
typedef pair<int,int>   II;
typedef vector<II>     VII;
typedef vector<int>     VI;
typedef vector< VI > 	VVI;
typedef long long int LL;
typedef  unsigned long long int ULL;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define SET(a,b) memset(a,b,sizeof(a))
#define LET(x,a) __typeof(a) x(a)
#define ALL(c) (c).begin(),(c).end()
#define si(n) scanf("%d",&n)
#define dout(n) printf("%d\n",n)
#define sll(n) scanf("%lld",&n)
#define lldout(n) printf("%lld\n",n)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
#define REP(i,a,b) for(int i = (int)a; i < (int)b; i++)
#define ROUNDOFFINT(d) d = (int)((double)d + 0.5)
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1)	{
cerr << name << " : " << arg1 << std::endl;}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
     const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);}
#else
#define trace(...)
#endif




#define ll long long
#define ld long double
#define N ((ll)301*1000)

struct Ant{
    ll x,y,id;
    int c;
};

bool cmp(Ant x,Ant y){return x.x<y.x;}

ll n,m,t,ans[N],cnt_l;
pair <ll,ll> b[N];
Ant a[N];
ll tmp[N];

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin>>n>>m>>t;
    for(int i=0;i<n;i++)
    {
        cin>>a[i].x>>a[i].c;
        a[i].id=i;
        a[i].y=a[i].x+(t%m)*(a[i].c==1?1:-1);
        if(a[i].y<=0)a[i].y+=m;
        if(a[i].y>m)a[i].y-=m;
        if(a[i].c==2)cnt_l++;
    }
    sort(a,a+n,cmp);
    ll shift=2*n-2*cnt_l;shift%=n;
    shift*=t/m;shift%=n;t%=m;
    for(int i=0;i<n;i++)tmp[(i+shift)%n]=a[i].id;
    for(int i=0;i<n;i++)a[i].id=tmp[i];
    
    for(int i=0;i<n;i++)b[i]={a[i].y,i};
    sort(b,b+n);
    
    ll hits[2]={};
    for(int q=0;q<2;q++)
        for(int i=0;i<n;i++)
            if(a[i].c!=a[b[q].second].c)
            {
                ll p=b[q].second;
                ll l=a[p].x,r=a[p].y;
                ld pos1=((ld)a[p].x+a[i].x)/2,pos2=pos1+(ld)m/2;
                if(pos2>m)pos2-=m;
                if(l<=r && a[p].c==1)hits[q]+=(l<pos1 && pos1<r)+(l<pos2 && pos2<r);
                if(l<=r && a[p].c==2)hits[q]+=(pos1<l || r<pos1)+(pos2<l || r<pos2);
                if(r<l && a[p].c==2)hits[q]+=(r<pos1 && pos1<l)+(r<pos2 && pos2<l);
                if(r<l && a[p].c==1)hits[q]+=(pos1<r || l<pos1)+(pos2<r || l<pos2);
            }
    ll id1=(b[0].second+hits[0]*(a[b[0].second].c==1?1:-1)+5*n)%n,id2=(b[1].second+hits[1]*(a[b[1].second].c==1?1:-1)+5*n)%n;
    for(int i=id1,j=0;j<n;i++,i%=n,j++)
        ans[a[i].id]=b[(j+(b[0].first==b[1].first && (id2+1)%n==id1))%n].first;
    for(int i=0;i<n;i++)cout<<ans[i]%m<<endl;
    return 0;
}