#include <bits/stdc++.h>
#pragma GCC optimize(2)
const int maxn = 1e5 + 5;
std::map<int, std::vector<int> > Reading;
struct Walk {
  int p, t, dir;
  int id;
} M[maxn];
int n, w, h;
int ansx[maxn], ansy[maxn];
inline bool Comp(int Alpha, int Beta) { return M[Alpha].p > M[Beta].p; }
int main() {
  scanf("%d%d%d", &n, &w, &h);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d%d", &M[i].dir, &M[i].p, &M[i].t);
    M[i].dir = M[i].dir == 1 ? 2 : 1;
    M[i].id = i;
    Reading[M[i].p - M[i].t].push_back(i);
  }
  for (std::map<int, std::vector<int> >::iterator it = Reading.begin();
       it != Reading.end(); it++) {
    std::vector<int> &Amadues = it->second;
    std::vector<int> R1, R2;
    for (unsigned p = 0; p < Amadues.size(); p++) {
      if (M[Amadues[p]].dir == 1) R1.push_back(M[Amadues[p]].p);
      if (M[Amadues[p]].dir == 2) R2.push_back(M[Amadues[p]].p);
    }
    std::sort(Amadues.begin(), Amadues.end(), Comp);
    std::sort(R1.begin(), R1.end()), std::sort(R2.begin(), R2.end());
    unsigned p1 = 0, p2 = 0;
    if (R1.size() > R2.size()) {
      for (unsigned p = 0; p < Amadues.size(); p++) {
        if (M[Amadues[p]].dir == 2) {
          ansx[Amadues[p]] = w, ansy[Amadues[p]] = R1[p1++];
        }
      }
      p1 = R1.size();
      for (unsigned p = 0; p < Amadues.size(); p++) {
        if (M[Amadues[p]].dir == 1) {
          if (p2 < R2.size())
            ansx[Amadues[p]] = R2[p2++], ansy[Amadues[p]] = h;
          else
            ansx[Amadues[p]] = w, ansy[Amadues[p]] = R1[--p1];
        }
      }
    } else {
      for (unsigned p = 0; p < Amadues.size(); p++) {
        if (M[Amadues[p]].dir == 1) {
          ansx[Amadues[p]] = R2[p2++], ansy[Amadues[p]] = h;
        }
      }
      p2 = R2.size();
      for (unsigned p = 0; p < Amadues.size(); p++) {
        if (M[Amadues[p]].dir == 2) {
          if (p1 < R1.size())
            ansx[Amadues[p]] = w, ansy[Amadues[p]] = R1[p1++];
          else
            ansx[Amadues[p]] = R2[--p2], ansy[Amadues[p]] = h;
        }
      }
    }
  }
  for (int i = 1; i <= n; i++) printf("%d %d\n", ansx[i], ansy[i]);
  return 0;
}
