#include <bits/stdc++.h>
using namespace std;
const long long M = 3e5 + 1000, N = 3e5 + 1000;
vector<pair<int, int> > so[M], sol[M];
set<int> s;
long long n, w, h, q = 1e5, r[N], o, p, t[M], x[N], y[N], xp[N], yp[N], l,
                   e = 0, d = 0, rd[N], pd[N];
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  std::set<int>::iterator it, id;
  cin >> n >> w >> h;
  p = 0;
  for (int i = 1; i <= n; i++) {
    cin >> rd[i] >> pd[i] >> t[i];
    t[i] -= pd[i];
    t[i] += q;
    if (rd[i] == 2) {
      x[i] = w;
      y[i] = pd[i];
      so[t[i]].push_back({y[i], i});
    } else {
      x[i] = pd[i];
      y[i] = h;
      sol[t[i]].push_back({x[i], i});
    }
    s.insert(t[i]);
    xp[i] = x[i];
    yp[i] = y[i];
  }
  it = s.begin();
  for (int j = 0; j < s.size(); j++) {
    sort(so[*it].begin(), so[*it].end());
    sort(sol[*it].begin(), sol[*it].end());
    o = so[*it].size();
    p = sol[*it].size();
    if (o == 0 || p == 0) {
      ++it;
      continue;
    }
    if (o > p) {
      for (int g = 0; g < o; g++) {
        if (g < o - p) {
          l = so[*it][g].second;
          e = so[*it][p + g].second;
          xp[l] = x[e];
          yp[l] = y[e];
        } else {
          l = so[*it][g].second;
          e = sol[*it][o - g - 1].second;
          xp[l] = x[e];
          yp[l] = y[e];
          l = sol[*it][g - o + p].second;
          e = so[*it][o - g - 1].second;
          xp[l] = x[e];
          yp[l] = y[e];
        }
      }
    } else if (o < p) {
      for (int g = 0; g < p; g++) {
        if (g < p - o) {
          l = sol[*it][g].second;
          e = sol[*it][g + o].second;
          xp[l] = x[e];
          yp[l] = y[e];
        } else {
          l = sol[*it][g].second;
          e = so[*it][p - g - 1].second;
          xp[l] = x[e];
          yp[l] = y[e];
          l = so[*it][g - p + o].second;
          e = sol[*it][p - g - 1].second;
          xp[l] = x[e];
          yp[l] = y[e];
        }
      }
    } else if (o == p) {
      for (int g = 0; g < o; g++) {
        l = so[*it][g].second;
        e = sol[*it][o - g - 1].second;
        xp[l] = x[e];
        yp[l] = y[e];
        l = sol[*it][g].second;
        e = so[*it][o - g - 1].second;
        xp[l] = x[e];
        yp[l] = y[e];
      }
    }
    ++it;
  }
  for (int i = 1; i <= n; i++) {
    cout << xp[i] << ' ' << yp[i] << '\n';
  }
  return 0;
}
