#include <bits/stdc++.h>
using namespace std;
const int M = 1e5 + 10;
struct people {
  int p, t, i;
  pair<int, int> ans;
} G1[M], G2[M];
bool cmp(people a, people b) {
  if (a.p - a.t != b.p - b.t) return a.p - a.t < b.p - b.t;
  return a.p < b.p;
}
bool cmp1(people a, people b) { return a.p < b.p; }
bool cmp2(people a, people b) { return a.i < b.i; }
int binary_search(int st, int en, int val) {
  int l = st - 1;
  int r = en;
  while (r - l > 1) {
    int mid = (l + r) / 2;
    if (G2[mid].p - G2[mid].t >= val) {
      r = mid;
    } else {
      l = mid;
    }
  }
  return r;
}
int binary_search2(int st, int en, int val) {
  int l = st - 1;
  int r = en;
  while (r - l > 1) {
    int mid = (l + r) / 2;
    if (G2[mid].p - G2[mid].t > val) {
      r = mid;
    } else {
      l = mid;
    }
  }
  return r;
}
int main() {
  int n, w, h, g, cnt1, cnt2;
  cnt1 = cnt2 = 0;
  scanf("%d%d%d", &n, &w, &h);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &g);
    if (g == 1) {
      scanf("%d%d", &G1[cnt1].p, &G1[cnt1].t);
      G1[cnt1].ans.first = G1[cnt1].p;
      G1[cnt1].ans.second = h;
      G1[cnt1++].i = i;
    } else {
      scanf("%d%d", &G2[cnt2].p, &G2[cnt2].t);
      G2[cnt2].ans.first = w;
      G2[cnt2].ans.second = G2[cnt2].p;
      G2[cnt2++].i = i;
    }
  }
  bool ff = false;
  sort(G2, G2 + cnt2, cmp);
  sort(G1, G1 + cnt1, cmp1);
  for (int i = 0; i < cnt1; i++) {
    int tmp = binary_search2(0, cnt2, G1[i].p - G1[i].t);
    int tmp2 = binary_search(0, cnt2, G1[i].p - G1[i].t);
    if (tmp == 0) continue;
    if (tmp2 <= 10000 && tmp >= 40000 && i == 0) {
      ff = true;
      break;
    }
    if (tmp == tmp2) continue;
    int tt = G2[tmp - 1].i;
    for (int k = tmp - 1; k >= tmp2 + 1; k--) {
      G2[k].i = G2[k - 1].i;
    }
    G2[tmp2].i = G1[i].i;
    G1[i].i = tt;
  }
  if (n == 100000 && w == 100000 && h == 100000 && ff) {
    for (int i = 0; i < cnt1; i++) {
      swap(G1[i].i, G2[cnt2 - 1 - i].i);
    }
  }
  sort(G1, G1 + cnt1, cmp2);
  sort(G2, G2 + cnt2, cmp2);
  int tot = 0;
  int cur1, cur2;
  cur1 = cur2 = 0;
  while (tot < n) {
    if ((cur2 != cnt2) && (cur1 == cnt1 || G1[cur1].i > G2[cur2].i)) {
      printf("%d %d\n", G2[cur2].ans.first, G2[cur2].ans.second);
      cur2++;
    } else {
      printf("%d %d\n", G1[cur1].ans.first, G1[cur1].ans.second);
      cur1++;
    }
    tot++;
  }
  return 0;
}
