#include <bits/stdc++.h>
using namespace std;
pair<int, int> endpos[100000];
vector<pair<pair<int, int>, int> > vs[200020];
int _harr[200020];
int poschg[100000];
int func(pair<pair<int, int>, int> a, pair<pair<int, int>, int> b) {
  if (a.first.first != b.first.first) {
    return a.first.first > b.first.first;
  }
  if (a.first.first == 1) {
    return a.first.second < b.first.second;
  }
  return a.first.second > b.first.second;
}
int main() {
  int n, w, h;
  scanf("%d%d%d", &n, &w, &h);
  int i;
  auto hasharr = vs + 100010;
  auto harr = _harr + 100010;
  for (i = 0; i < n; ++i) {
    int g, p, t;
    scanf("%d%d%d", &g, &p, &t);
    if (g == 1) {
      endpos[i] = make_pair(p, h);
    } else {
      endpos[i] = make_pair(w, p);
    }
    int hash = t - p;
    hasharr[hash].push_back(make_pair(make_pair(g, p), i));
    if (g == 2) {
      harr[hash]++;
    }
  }
  for (i = -100000; i <= 100000; ++i) {
    sort(hasharr[i].begin(), hasharr[i].end(), func);
    int sz = (int)hasharr[i].size();
    int x = harr[i];
    int mn = x;
    int j;
    for (j = 0; j < sz; ++j) {
      poschg[hasharr[i][j].second] = hasharr[i][(j + mn) % sz].second;
    }
  }
  for (i = 0; i < n; ++i) {
    int newidx = poschg[i];
    printf("%d %d\n", endpos[newidx].first, endpos[newidx].second);
  }
  return 0;
}
