#include <bits/stdc++.h>
using namespace std;
template <typename T>
void scan(T &angka) {
  angka = 0;
  char input = getchar();
  T kali = 1;
  while (!(48 <= input && input <= 57)) {
    if (input == '-') kali = -1;
    input = getchar();
  }
  while (48 <= input && input <= 57)
    angka = (angka << 3) + (angka << 1) + input - 48, input = getchar();
  angka *= kali;
}
template <typename T1, typename T2>
void scan(T1 &angka1, T2 &angka2) {
  scan(angka1);
  scan(angka2);
}
int n, w, h, lasttime;
vector<pair<pair<int, int>, pair<int, int> > > daftar;
vector<pair<int, int> > pos[2];
pair<int, int> ans[100005];
void outputkan() {
  for (int i = 0; i < n; i++) printf("%d %d\n", ans[i].first, ans[i].second);
}
pair<int, int> maksimum(int jenis, int pos) {
  if (jenis == 0)
    return make_pair(pos, h);
  else
    return make_pair(w, pos);
}
void solve() {
  if (pos[0].size() == 0) {
    for (auto isi : pos[1]) ans[isi.second] = maksimum(1, isi.first);
    return;
  }
  if (pos[1].size() == 0) {
    for (auto isi : pos[0]) ans[isi.second] = maksimum(0, isi.first);
    return;
  }
  int jarak;
  for (int i = 0; i < pos[0].size(); i++) {
    jarak = min((int)pos[1].size() - 1, (int)pos[0].size() - (i + 1));
    if (i + jarak == (pos[0].size() - 1))
      ans[pos[0][i].second] = maksimum(1, pos[1][jarak].first);
    else
      ans[pos[0][i].second] = maksimum(0, pos[0][i + jarak + 1].first);
  }
  for (int i = 0; i < pos[1].size(); i++) {
    jarak = min((int)pos[1].size() - (i + 1), (int)pos[0].size() - 1);
    if (i + jarak == (pos[1].size() - 1))
      ans[pos[1][i].second] = maksimum(0, pos[0][jarak].first);
    else
      ans[pos[1][i].second] = maksimum(1, pos[1][i + jarak + 1].first);
  }
}
void reset() {
  for (int i = 0; i < 2; i++) pos[i].clear();
}
int main() {
  scan(n), scan(w, h);
  daftar.resize(n);
  for (int i = 0; i < n; i++) {
    scan(daftar[i].first.second, daftar[i].second.first);
    scan(daftar[i].first.first);
    daftar[i].first.first -= daftar[i].second.first;
    daftar[i].second.second = i;
  }
  sort((daftar).begin(), (daftar).end());
  lasttime = daftar[0].first.first;
  for (auto isi : daftar) {
    if (isi.first.first != lasttime) {
      solve();
      reset();
      lasttime = isi.first.first;
    }
    pos[isi.first.second - 1].push_back(isi.second);
  }
  solve();
  outputkan();
}
