#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
const int N = 100010;
struct yts {
  int op, bh, x, y, d;
} e[N];
bool cmp(yts a, yts b) {
  if (a.d != b.d) return a.d < b.d;
  if (a.op != b.op) return a.op < b.op;
  if (a.op == 1)
    return a.x < b.x;
  else
    return a.y < b.y;
}
int w, h;
pair<int, int> ans[N];
pair<int, int> getans(yts a) {
  if (a.op == 1)
    return make_pair(a.x, h);
  else
    return make_pair(w, a.y);
}
void work(int l, int r) {
  static yts v[N], h[N];
  int i, j, s1 = 0, s2 = 0;
  for (i = l; i <= r; i++) {
    if (e[i].op == 2) break;
    v[++s1] = e[i];
  }
  for (; i <= r; i++) h[++s2] = e[i];
  if (s1 < s2) {
    for (i = 1; i <= s2; i++) swap(v[i], h[i]);
    swap(s1, s2);
  }
  for (i = 1; i + s2 <= s1; i++) ans[v[i].bh] = getans(v[i + s2]);
  for (i = 1; i <= s2; i++) {
    ans[v[s1 - i + 1].bh] = getans(h[i]);
    ans[h[i].bh] = getans(v[s2 - i + 1]);
  }
}
int main() {
  int i, j, n;
  scanf("%d%d%d", &n, &w, &h);
  for (i = 1; i <= n; i++) {
    int op, x, t;
    scanf("%d%d%d", &op, &x, &t);
    e[i].op = op;
    e[i].bh = i;
    if (op == 1)
      e[i].x = x, e[i].y = -t;
    else
      e[i].x = -t, e[i].y = x;
    e[i].d = e[i].x + e[i].y;
  }
  sort(e + 1, e + n + 1, cmp);
  e[0].d = e[1].d - 1;
  for (i = 1; i <= n; i++) {
    if (e[i].d == e[i - 1].d) continue;
    for (j = i; j <= n; j++)
      if (e[i].d != e[j].d) break;
    work(i, j - 1);
  }
  for (i = 1; i <= n; i++) printf("%d %d\n", ans[i].first, ans[i].second);
  return 0;
}
