#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
int n, w, h;
vector<pair<int, int> > hen, shu;
int pt[100010], lo[100010], ti[100010];
queue<int> que;
vector<int> cmps, caps;
int ans[100010];
pair<int, int> output[100010];
bool cmp(int a, int b) { return lo[a] < lo[b]; }
bool cmp2(int a, int b) { return lo[a] > lo[b]; }
int main() {
  memset(ans, -1, sizeof(ans));
  scanf("%d%d%d", &n, &w, &h);
  for (int i = 0; i < n; i += 1) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    pt[i] = a;
    lo[i] = b;
    ti[i] = c;
    if (a == 1)
      shu.push_back(make_pair(b - c, i));
    else
      hen.push_back(make_pair(b - c, i));
  }
  sort(shu.begin(), shu.end());
  sort(hen.begin(), hen.end());
  bool flag = false;
  int time = -1, k1 = 0, k2 = 0;
  for (int i = 0; i < shu.size() + 1; i++) {
    if (flag == false) {
      time = i;
      flag = true;
      continue;
    } else if (i != shu.size() && shu[time].first == shu[i].first)
      continue;
    else {
      for (k2 = k1; k2 < hen.size() && hen[k2].first < shu[time].first; k2++)
        ans[hen[k2].second] = hen[k2].second;
      for (k1 = k2; k2 < hen.size() && hen[k2].first == shu[time].first; k2++)
        ;
      cmps.clear();
      for (int j = k1; j < k2; j++) cmps.push_back(hen[j].second);
      sort(cmps.begin(), cmps.end(), cmp2);
      while (!que.empty()) que.pop();
      for (int j : cmps) que.push(j);
      caps.clear();
      for (int j = time; j < i; j++) caps.push_back(shu[j].second);
      sort(caps.begin(), caps.end(), cmp);
      if (!que.empty()) {
        for (int j = 0; j < caps.size(); j++) {
          ans[caps[j]] = que.front();
          que.pop();
          que.push(caps[j]);
        }
        for (int j = 0; j < cmps.size(); j++) {
          ans[cmps[j]] = que.front();
          que.pop();
        }
      } else {
        for (int j = 0; j < caps.size(); j++) {
          ans[caps[j]] = caps[j];
        }
      }
      k1 = k2;
      time = i;
    }
  }
  for (; k2 < hen.size(); k2++) ans[hen[k2].second] = hen[k2].second;
  for (int i = 0; i < n; i++) {
    int po = ans[i], x, y;
    if (pt[i] == 1) {
      x = lo[i];
      y = h;
    } else {
      x = w;
      y = lo[i];
    }
    if (po != -1)
      output[po] = make_pair(x, y);
    else
      printf("error\n");
  }
  for (int i = 0; i < n; i++) {
    printf("%d %d\n", output[i].first, output[i].second);
  }
  return 0;
}
