#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <typename S, typename T>
void xmin(S &a, T const &b) {
  if (b < a) a = b;
}
template <typename S, typename T>
void xmax(S &a, T const &b) {
  if (b > a) a = b;
}
signed main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(false);
  ll n, w, h;
  cin >> n >> w >> h;
  vector<array<ll, 3> > dan(n);
  map<ll, vector<ll> > bu;
  for (auto &e : dan) {
    cin >> e[0] >> e[1] >> e[2];
  }
  for (ll i = 0; i < n; ++i) {
    auto const &e = dan[i];
    bu[e[1] - e[2]].push_back(i);
  }
  vector<pair<ll, ll> > ans(n, make_pair(-1, -1));
  for (auto const &e : bu) {
    vector<pair<ll, ll> > tmp;
    vector<pair<ll, ll> > tmp2;
    for (ll i : e.second) {
      auto const &f = dan[i];
      if (f[0] == 1) {
        tmp.emplace_back(f[1], i);
        tmp2.emplace_back(f[1], i);
      } else {
        tmp.emplace_back(-f[1], i);
        tmp2.emplace_back(2 * (w + h) - f[1], i);
      }
    }
    sort(tmp.begin(), tmp.end());
    sort(tmp2.begin(), tmp2.end());
    for (ll i = 0; i < (ll)tmp.size(); ++i) {
      auto const &f = dan[tmp2[i].second];
      pair<ll, ll> pos(-1, -1);
      if (f[0] == 1) {
        pos = make_pair(f[1], h);
      } else {
        pos = make_pair(w, f[1]);
      }
      ans[tmp[i].second] = pos;
    }
  }
  for (auto const &e : ans) {
    cout << e.first << " " << e.second << "\n";
  }
  return 0;
}
