#include <bits/stdc++.h>
using namespace std;
struct node {
  int x, y, num;
  inline void operator=(const node &v) { x = v.x, y = v.y, num = v.num; }
};
map<int, deque<node *> > m;
int n, w, h;
node a[100010];
deque<int> b;
int x[100010], y[100010];
inline bool cmp1(node *s, node *t) { return s->y > t->y; }
inline bool cmp2(node *s, node *t) { return s->x > t->x; }
int main() {
  int i, j, k, g, p, t;
  scanf("%d%d%d", &n, &w, &h);
  for (i = 1; i <= n; ++i) {
    scanf("%d%d%d", &g, &p, &t);
    a[i].num = i;
    if (g & 1) {
      a[i].x = p;
      a[i].y = -t;
    } else {
      a[i].x = -t;
      a[i].y = p;
    }
    if (m.find(a[i].x + a[i].y) != m.end()) {
      m[a[i].x + a[i].y].push_back(a + i);
    } else {
      deque<node *> vec;
      m[a[i].x + a[i].y] = vec;
      m[a[i].x + a[i].y].push_back(a + i);
      b.push_back(a[i].x + a[i].y);
    }
  }
  for (i = 0; i < b.size(); i++) {
    deque<node *> vec, v1, v2;
    vec = m[b[i]];
    for (j = 0; j < vec.size(); j++) {
      if (vec[j]->x > 0) {
        v1.push_back(vec[j]);
      }
      if (vec[j]->y > 0) {
        v2.push_back(vec[j]);
      }
    }
    stable_sort(v1.begin(), v1.end(), cmp1);
    stable_sort(v2.begin(), v2.end(), cmp2);
    vector<int> p1, p2;
    for (j = 0; j < v1.size(); j++) {
      p1.push_back(v1[j]->x);
    }
    for (j = 0; j < v2.size(); j++) {
      p2.push_back(v2[j]->y);
    }
    j = k = 0;
    for (j = 0; j < v1.size(); j++) {
      v2.push_front(v1[j]);
      v1[j] = v2.back();
      v2.pop_back();
    }
    for (j = 0; j < v1.size(); j++) {
      x[v1[j]->num] = p1[j];
      y[v1[j]->num] = h;
    }
    for (j = 0; j < v2.size(); j++) {
      x[v2[j]->num] = w;
      y[v2[j]->num] = p2[j];
    }
  }
  for (i = 1; i <= n; i++) {
    printf("%d %d\n", x[i], y[i]);
  }
}
