#include <bits/stdc++.h>
using namespace std;
int n, w, h;
struct dancer {
  int x, y, t, it;
  dancer() {}
  dancer(int x, int y, int t, int it) : x(x), y(y), t(t), it(it) {}
};
vector<dancer> hor, ver, alld;
deque<int> ho[250000];
vector<int> hoinit[250000];
int add = 125000;
bool cmp(const dancer &lhs, const dancer &rhs) {
  int mxl = max(lhs.x, lhs.y);
  int mxr = max(rhs.x, rhs.y);
  return mxl < mxr;
}
bool cmp2(const dancer &lhs, const dancer &rhs) { return lhs.it < rhs.it; }
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> w >> h;
  for (int i = 0; i < n; i++) {
    int g, p, t;
    cin >> g >> p >> t;
    if (g == 1)
      ver.push_back(dancer(p, 0, t, i));
    else
      hor.push_back(dancer(0, p, t, i));
  }
  sort(ver.begin(), ver.end(), cmp);
  sort(hor.begin(), hor.end(), cmp);
  int m = hor.size();
  for (int i = 0; i < m; i++) {
    int diff = hor[i].y - hor[i].t + add;
    ho[diff].push_back(hor[i].it);
    hoinit[diff].push_back(i);
  }
  for (int i = 0; i < ver.size(); i++) {
    int diff = ver[i].x - ver[i].t + add;
    if (!ho[diff].empty()) {
      int tmp = ho[diff].back();
      ho[diff].pop_back();
      ho[diff].push_front(ver[i].it);
      ver[i].it = tmp;
    }
  }
  for (int diff = 0; diff < 250000; diff++) {
    if (!ho[diff].empty()) {
      for (int j = 0; j < ho[diff].size(); j++) {
        int init = hoinit[diff][j];
        int tmp = ho[diff][j];
        hor[init].it = tmp;
      }
    }
  }
  for (auto u : hor) alld.push_back(u);
  for (auto u : ver) alld.push_back(u);
  sort(alld.begin(), alld.end(), cmp2);
  for (auto u : alld) {
    if (u.x == 0) u.x = w;
    if (u.y == 0) u.y = h;
    cout << u.x << ' ' << u.y << endl;
  }
  return 0;
}
