#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int h, w, n, R[131072 * 2 + 5], C[131072 * 2 + 5], rk[100000 + 5],
    Ansx[100000 + 5], Ansy[100000 + 5];
struct data {
  int g, t, p, T, id;
} s[100000 + 5];
bool cmp(const data& a, const data& b) { return a.T < b.T; }
void Renew(int* T, int x, int v) {
  for (T[x += 131072] = v, x >>= 1; x; x >>= 1)
    T[x] = T[x << 1] + T[x << 1 | 1];
}
int Query(int* T, int l, int r) {
  int sum = 0;
  for (l += 131072 - 1, r += 131072 + 1; l ^ r ^ 1; l >>= 1, r >>= 1) {
    if (~l & 1) sum += T[l + 1];
    if (r & 1) sum += T[r - 1];
  }
  return sum;
}
int Solve(int* T, int k) {
  int x = 1;
  for (; x <= 131072;) {
    if (T[x << 1] >= k)
      x <<= 1;
    else
      k -= T[x << 1], x = x << 1 | 1;
  }
  return x - 131072;
}
int main() {
  n = read();
  w = read();
  h = read();
  for (int i = 1; i <= n; ++i) {
    s[i].g = read(), s[i].p = read(), s[i].t = read();
    s[i].T = s[i].p - s[i].t;
    s[i].id = i;
  }
  sort(s + 1, s + n + 1, cmp);
  for (int i = 1, j; i <= n; i = j + 1) {
    for (j = i; j < n && s[j + 1].T == s[i].T;) ++j;
    int tot1 = 0, tot2 = 0;
    for (int k = i; k <= j; ++k)
      if (s[k].g == 1)
        Renew(C, s[k].p, 1), ++tot1;
      else
        Renew(R, s[k].p, 1), ++tot2;
    for (int k = i; k <= j; ++k)
      if (s[k].g == 1) {
        int y2 = Query(C, s[k].p + 1, 131072), y3 = tot1 - y2;
        if (tot2 > y2)
          Ansx[s[k].id] = w, Ansy[s[k].id] = Solve(R, y2 + 1);
        else
          Ansy[s[k].id] = h, Ansx[s[k].id] = Solve(C, y3 + tot2);
      } else {
        int y2 = Query(R, s[k].p + 1, 131072), y3 = tot2 - y2;
        if (tot1 > y2)
          Ansy[s[k].id] = h, Ansx[s[k].id] = Solve(C, y2 + 1);
        else
          Ansx[s[k].id] = w, Ansy[s[k].id] = Solve(R, y3 + tot1);
      }
    for (int k = i; k <= j; ++k)
      if (s[k].g == 1)
        Renew(C, s[k].p, 0);
      else
        Renew(R, s[k].p, 0);
  }
  for (int i = 1; i <= n; ++i) printf("%d %d\n", Ansx[i], Ansy[i]);
  return 0;
}
