#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5;
vector<long long> V, H;
unordered_map<long long, vector<long long>> G;
unordered_map<long long, long long> sz;
unordered_map<long long, vector<long long>>::iterator it;
long long a[N][3], ans[N];
bool comp(int i, int j) {
  pair<long long, long long> p, q;
  p.first = a[i][1] - a[i][2];
  q.first = a[j][1] - a[j][2];
  p.second = a[i][1];
  q.second = a[j][1];
  return p < q;
}
int main() {
  ios_base::sync_with_stdio(false);
  long long n, vz, hz;
  cin >> n >> vz >> hz;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 3; j++) cin >> a[i][j];
    if (a[i][0] == 1)
      V.push_back(i);
    else
      H.push_back(i);
  }
  sort(V.begin(), V.end(), comp);
  sort(H.begin(), H.end(), comp);
  for (long long i : V) {
    long long cnt = a[i][1] - a[i][2];
    G[cnt].push_back(i);
  }
  for (it = G.begin(); it != G.end(); it++) sz[it->first] = (it->second).size();
  for (long long i : H) {
    long long cnt = a[i][1] - a[i][2];
    G[cnt].push_back(i);
  }
  for (it = G.begin(); it != G.end(); it++) {
    if ((it->second).size() > sz[it->first])
      reverse((it->second).begin() + sz[it->first], (it->second).end());
  }
  for (it = G.begin(); it != G.end(); it++) {
    long long s = (it->second).size() - sz[it->first];
    for (int j = 0; j < (it->second).size(); j++) {
      long long jx = j + s;
      jx %= (it->second).size();
      ans[(it->second)[j]] = (it->second)[jx];
    }
  }
  for (int i = 0; i < n; i++) {
    long long ix = ans[i];
    if (a[ix][0] == 1) {
      cout << a[ix][1] << " " << hz << endl;
    } else {
      cout << vz << " " << a[ix][1] << endl;
    }
  }
}
