#include <bits/stdc++.h>
using namespace std;
struct node {
  int pos;
  int id;
  friend bool operator<(const node &a, const node &b) { return a.pos < b.pos; }
} ans[100005];
int n, w, h;
vector<node> v[2][200005];
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> w >> h;
  for (int i = 1, p, g, t; i <= n; i++) {
    cin >> g >> p >> t;
    v[g - 1][p - t + 100000].push_back((node){p, i});
  }
  for (int i = 0; i <= 200000; i++) {
    sort(v[0][i].begin(), v[0][i].end());
    sort(v[1][i].begin(), v[1][i].end());
  }
  for (int i = 0; i <= 200000; i++) {
    for (int j = 0; j < v[0][i].size(); j++) {
      if (v[0][i].size() - j - 1 >= v[1][i].size())
        ans[v[0][i][j].id] = (node){v[0][i][j + v[1][i].size()].pos, h};
      else
        ans[v[0][i][j].id] = (node){w, v[1][i][v[0][i].size() - j - 1].pos};
    }
    for (int j = 0; j < v[1][i].size(); j++) {
      if (v[1][i].size() - j - 1 >= v[0][i].size())
        ans[v[1][i][j].id] = (node){w, v[1][i][j + v[0][i].size()].pos};
      else
        ans[v[1][i][j].id] = (node){v[0][i][v[1][i].size() - j - 1].pos, h};
    }
  }
  for (int i = 1; i <= n; i++) cout << ans[i].pos << ' ' << ans[i].id << '\n';
  return 0;
}
