#include <bits/stdc++.h>
using namespace std;
ifstream in("file.in");
ofstream out("file.out");
struct om {
  int p, t, id;
} a[100005], b[100005];
int n, w, h, cnt1[200005], cnt2[200005], ans[100005], v[200005], k, m, first,
    nibab[100005];
pair<int, int> fk[100005];
queue<int> q[200005];
bool comp(om a, om b) { return a.p < b.p; }
int main() {
  ios_base ::sync_with_stdio(0);
  cin.tie();
  cin >> n >> w >> h;
  for (int i = 1; i <= n; i++) {
    cin >> first;
    if (first == 1) {
      k++;
      cin >> a[k].p >> a[k].t;
      a[k].id = i;
      cnt1[a[k].t - a[k].p + 100000]++;
    } else {
      m++;
      cin >> b[m].p >> b[m].t;
      b[m].id = i;
      cnt2[b[m].t - b[m].p + 100000]++;
    }
  }
  sort(a + 1, a + k + 1, comp);
  sort(b + 1, b + m + 1, comp);
  for (int i = m; i >= 1; i--) {
    q[b[i].t - b[i].p + 100000].push(b[i].id);
  }
  for (int i = 1; i <= k; i++) {
    q[a[i].t - a[i].p + 100000].push(a[i].id);
  }
  for (int i = 1; i <= k; i++) {
    ans[a[i].id] = q[a[i].t - a[i].p + 100000].front();
    q[a[i].t - a[i].p + 100000].pop();
  }
  for (int i = m; i >= 1; i--) {
    while (q[b[i].t - b[i].p + 100000].size())
      q[b[i].t - b[i].p + 100000].pop();
  }
  for (int i = 1; i <= k; i++) {
    while (q[a[i].t - a[i].p + 100000].size())
      q[a[i].t - a[i].p + 100000].pop();
  }
  for (int i = k; i >= 1; i--) {
    q[a[i].t - a[i].p + 100000].push(a[i].id);
  }
  for (int i = 1; i <= m; i++) {
    q[b[i].t - b[i].p + 100000].push(b[i].id);
  }
  for (int i = 1; i <= m; i++) {
    ans[b[i].id] = q[b[i].t - b[i].p + 100000].front();
    q[b[i].t - b[i].p + 100000].pop();
  }
  for (int i = 1; i <= n; i++) nibab[ans[i]] = i;
  for (int i = 1; i <= k; i++) {
    fk[a[i].id] = {a[i].p, h};
  }
  for (int i = 1; i <= m; i++) {
    fk[b[i].id] = {w, b[i].p};
  }
  for (int i = 1; i <= n; i++) {
    cout << fk[nibab[i]].first << ' ' << fk[nibab[i]].second << '\n';
  }
}
