#include <bits/stdc++.h>
using namespace std;
int n, w, h, an[3][100005], now[100005], cnt = 1, cnt1 = 1, cnt2 = 1,
                                         lol[100005];
pair<pair<int, int>, pair<int, int> > pr[100005];
map<int, int> mp[3];
vector<int> vt[3][100005], v;
void process(int ex, int wye) {
  int tmp, siz1 = vt[1][ex].size(), siz2 = vt[2][wye].size();
  for (int i = siz2 - 1; i >= 0; i--) v.push_back(vt[2][wye][i]);
  for (int i = 0; i < siz1; i++) v.push_back(vt[1][ex][i]);
  int siz = v.size(), j = 0;
  for (int i = 0; i < siz1; i++, j++) now[v[j]] = vt[1][ex][i];
  for (int i = siz2 - 1; i >= 0; i--, j++) now[v[j]] = vt[2][wye][i];
  v.clear();
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  scanf("%d%d%d", &n, &w, &h);
  for (int i = 1, t, tmp; i <= n; i++) {
    scanf("%d%d%d", &pr[i].first.first, &pr[i].first.second,
          &pr[i].second.first);
    now[i] = pr[i].second.second = i;
  }
  sort(pr + 1, pr + n + 1);
  for (int i = 1, t, pos, tmp; i <= n; i++) {
    tmp = pr[i].second.first - pr[i].first.second;
    t = pr[i].first.first, pos = pr[i].second.second;
    if (t == 1) {
      an[1][pos] = pr[i].first.second, an[2][pos] = h;
      if (!mp[1].count(tmp)) {
        mp[1][tmp] = cnt1;
        cnt1++;
      }
      vt[1][mp[1][tmp]].push_back(pos);
      lol[mp[1][tmp]] = tmp;
    } else {
      an[1][pos] = w, an[2][pos] = pr[i].first.second;
      if (!mp[2].count(tmp)) {
        mp[2][tmp] = cnt2;
        cnt2++;
      }
      vt[2][mp[2][tmp]].push_back(pos);
    }
  }
  for (int i = 1; i < cnt1; i++) {
    if (mp[2].count(lol[i])) process(i, mp[2][lol[i]]);
  }
  for (int i = 1; i <= n; i++) printf("%d %d\n", an[1][now[i]], an[2][now[i]]);
  return 0;
}
