#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

typedef long double ld;
typedef long long ll;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define pb push_back
#define mp make_pair
#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const ld eps = 1e-9;
const ld pi = acos((ld) -1.0);

const int mod = (int) 1e9 + 7;

void add(int &x, int y) {
  if ((x += y) >= mod) {
    x -= mod;
  }
}

int mult(int x, int y) {
  return (long long) x * y % mod;
}

int power(int x, int pw) {
  int res = 1;
  for (; pw; pw >>= 1) {
    if (pw & 1) {
      res = mult(res, x);
    }
    x = mult(x, x);
  }
  return res;
}

void precalc() {
}


const int maxn = (int) 1e5 + 10;
int n, L, T;
int a[maxn], b[maxn];

int read() {
  if (scanf("%d%d%d", &n, &L, &T) < 2) {
    return 0;
  }
  for (int i = 0; i < n; ++i) {
    scanf("%d%d", a + i, b + i);
    --b[i];
  }
  return 1;
}

int ans[maxn];

void solve() {
  for (int iter = 0; iter < 2; ++iter) {
    vector<int> xs;
    vector<int> gor;
    for (int i = 0; i < n; ++i) {
      if (b[i]) {
        xs.pb(a[i]);
      } else {
        gor.pb(a[i]);
      }
    }
    for (int i = 0; i < n; ++i) {
      if (!b[i]) {
        auto &res = ans[!iter ? i : (n - 1 - i)];
        if (!sz(xs)) {
          res = (a[i] + T) % L;
          continue;
        }
        int s0 = lower_bound(gor.begin(), gor.end(), a[i]) - gor.begin();
        int t0 = lower_bound(xs.begin(), xs.end(), a[i]) - xs.begin();
        int left = -1, right = inf;
        while (left + 1 < right) {
          int mid = (left + right) / 2;
          int s = (s0 - (mid + 1) / 2);
          int t = (t0 + mid / 2);

          int ns = s % sz(gor);
          if (ns < 0) {
            ns += sz(gor);
          }
          int nt = t % sz(xs);
          if (nt < 0) {
            nt += sz(xs);
          }

          long long pass = (xs[nt] - gor[ns]) + (t - nt) / sz(xs) * (long long) L + (ns - s) / sz(gor) * (long long) L;
          if (pass <= 2ll * T) {
            left = mid;
          } else {
            right = mid;
          }
        }

        //eprintf("s0 = %d, t0 = %d, left = %d\n", s0, t0, left);

        if (left & 1) {
          res = (-(left + 1) / 2 + s0) % sz(gor);
          if (res < 0) {
            res += sz(gor);
          }
          res = gor[res] + T;
        } else {
          res = (t0 + left / 2) % sz(xs);
          res = xs[res] - T;
        }
        res %= L;
        if (res < 0) {
          res += L;
        }
      }
    }
    for (int i = 0; i < n; ++i) {
      a[i] = L - 1 - a[i];
      b[i] ^= 1;
    }
    reverse(a, a + n);
    reverse(b, b + n);
  }

  for (int i = 0; i < n; ++i) {
    if (b[i]) {
      ans[i] = L - 1 - ans[i];
    }
    printf("%d\n", ans[i]);
  }
}

int main() {
  precalc();
#ifdef LOCAL
  freopen(TASK ".out", "w", stdout);
  assert(freopen(TASK ".in", "r", stdin));
#endif

  while (1) {
    if (!read()) {
      break;
    }
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 2728