#include <bits/stdc++.h>
using namespace std;
const int NN = 50010;
const int INF = 0x3f3f3f3f;
const int MOD = 100000, STA = 8000010;
const long long LNF = 1LL << 60;
const double EPS = 1e-8;
const double OO = 1e15;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, 1, 0, -1};
const int day[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline int sign(double x) { return (x > EPS) - (x < -EPS); }
template <class T>
T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
template <class T>
T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
template <class T>
inline T lcm(T a, T b, T d) {
  return a / d * b;
}
template <class T>
inline T Min(T a, T b) {
  return a < b ? a : b;
}
template <class T>
inline T Max(T a, T b) {
  return a > b ? a : b;
}
template <class T>
inline T Min(T a, T b, T c) {
  return min(min(a, b), c);
}
template <class T>
inline T Max(T a, T b, T c) {
  return max(max(a, b), c);
}
template <class T>
inline T Min(T a, T b, T c, T d) {
  return min(min(a, b), min(c, d));
}
template <class T>
inline T Max(T a, T b, T c, T d) {
  return max(max(a, b), max(c, d));
}
int N, M, T;
int n, m, x, t, w, h;
map<int, deque<int> > Q;
struct TT {
  int g, p, t, id;
} E[101111];
int tp[101111], a[101111], b[101111];
bool cp(TT a, TT b) { return a.p < b.p; }
void init(int x, int now) {
  for (int i = 1; i <= n; i++) {
    if (E[i].g == x) Q[E[i].t - E[i].p].push_back(i);
  }
  for (int i = 1; i <= n; i++)
    if (E[i].g != x) {
      auto p = Q.find(E[i].t - E[i].p);
      if (p == Q.end() || p->second.empty()) {
        tp[i] = i;
      } else {
        tp[i] = p->second.back();
        p->second.pop_back();
        p->second.push_front(i);
      }
    }
  Q.clear();
}
int main() {
  scanf("%d%d%d", &n, &w, &h);
  int g, p, t;
  for (int i = 1; i <= n; i++) {
    scanf("%d%d%d", &E[i].g, &E[i].p, &E[i].t);
    E[i].id = i;
  }
  sort(E + 1, E + n + 1, cp);
  init(1, 2);
  init(2, 1);
  for (int i = 1; i <= n; i++) {
    if (E[i].g == 1) {
      a[E[tp[i]].id] = E[i].p;
      b[E[tp[i]].id] = h;
    } else {
      a[E[tp[i]].id] = w;
      b[E[tp[i]].id] = E[i].p;
    }
  }
  for (int i = 1; i <= n; i++) {
    printf("%d %d\n", a[i], b[i]);
  }
  return 0;
}
