#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
int n, w, h;
struct fc {
  int pos, t;
  int endx, endy;
  int idx;
};
fc xp[MAXN], yp[MAXN];
unordered_map<int, int> fy;
unordered_map<int, int> fx;
int invfy[MAXN], invfx[MAXN];
int cntx, cnty;
bool cmp(const fc &a, const fc &b) {
  if (a.pos == b.pos) return a.t < b.t;
  return a.pos < b.pos;
}
struct Node {
  int id;
  int x, y;
};
queue<int> qx[MAXN];
queue<int> qy[MAXN];
pair<int, int> ans[MAXN];
int main() {
  scanf("%d%d%d", &n, &w, &h);
  for (int i = 1; i <= n; i++) {
    int id, pos, t;
    scanf("%d%d%d", &id, &pos, &t);
    if (id == 1)
      xp[cntx++] = {pos, t, pos, h, i};
    else
      yp[cnty++] = {pos, t, w, pos, i};
  }
  sort(xp, xp + cntx, cmp);
  sort(yp, yp + cnty, cmp);
  int idycnt = 0, idxcnt = 0;
  for (int i = cnty - 1; i >= 0; i--) {
    int tmpid = yp[i].pos - yp[i].t;
    if (!fy.count(tmpid)) {
      fy[tmpid] = idycnt++;
    }
    qy[fy[tmpid]].push(yp[i].idx);
  }
  for (int i = cntx - 1; i >= 0; i--) {
    int tmpid = xp[i].pos - xp[i].t;
    if (!fx.count(tmpid)) {
      fx[tmpid] = idxcnt++;
    }
    qx[fx[tmpid]].push(xp[i].idx);
  }
  for (int i = 0; i < cntx; i++) {
    int tmp = xp[i].pos - xp[i].t;
    if (fy.count(tmp)) {
      int tmpid = fy[tmp];
      int now = xp[i].idx;
      qy[tmpid].push(now);
      now = qy[tmpid].front();
      qy[tmpid].pop();
      ans[now] = {xp[i].endx, xp[i].endy};
    } else {
      ans[xp[i].idx] = {xp[i].endx, xp[i].endy};
    }
  }
  for (int i = 0; i < cnty; i++) {
    int tmp = yp[i].pos - yp[i].t;
    if (fx.count(tmp)) {
      int tmpid = fx[tmp];
      int now = yp[i].idx;
      qx[tmpid].push(now);
      now = qx[tmpid].front();
      qx[tmpid].pop();
      ans[now] = {yp[i].endx, yp[i].endy};
    } else {
      ans[yp[i].idx] = {yp[i].endx, yp[i].endy};
    }
  }
  for (int i = 1; i <= n; i++) printf("%d %d\n", ans[i].first, ans[i].second);
}
