#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000043;
const long long linf = 1LL << 62;
const long long mod7 = 1000000007;
const long long mod9 = 1000000009;
long double PI = 3.141592653589793238462643383279502884197169399375;
template <class T>
inline const T sqr(const T& x) {
  return x * x;
}
long long gcd(long long a, long long b) {
  while (b) {
    a %= b;
    swap(a, b);
  }
  return a;
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
long long popcnt(long long mask) {
  long long cnt = 0;
  while (mask) cnt++, mask = (mask - 1) & mask;
  return cnt;
}
long long powi(long long a, long long b, long long mod = 1000000007) {
  long long c = 1;
  while (b) {
    if (b & 1) c = (c * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return c;
}
bool isprime(long long n) {
  if (n < 2) return 0;
  for (long long i = 2; i * i <= n; i++)
    if (n % i == 0) return 0;
  return 1;
}
struct Node {
  int x;
  int y;
  int id;
  int sz;
  Node* l;
  Node* r;
  Node() {}
  Node(int x, int y, Node* l = 0, Node* r = 0);
  void rsz();
};
inline int size(Node* a) { return (a != 0 ? a->sz : 0); }
Node::Node(int x, int y, Node* l, Node* r) : x(x), y(y), l(l), r(r) { rsz(); }
inline void Node::rsz() { sz = size(l) + size(r) + 1; }
void split(Node* a, int c, int alr, Node*& l, Node*& r) {
  if (a == 0) {
    l = 0, r = 0;
    return;
  }
  Node* nt = 0;
  if (alr + size(a->l) + 1 <= c) {
    l = a;
    split(a->r, c, alr + size(a->l) + 1, l->r, r);
    l->rsz();
  } else {
    r = a;
    split(a->l, c, alr, l, r->l);
    r->rsz();
  }
}
Node* merge(Node* a, Node* b) {
  if (a == 0) return b;
  if (b == 0) return a;
  if (a->y > b->y) {
    a->r = merge(a->r, b);
    a->rsz();
    return a;
  } else {
    b->l = merge(a, b->l);
    b->rsz();
    return b;
  }
}
Node* get(Node* a, int x, int alr) {
  if (alr + 1 + size(a->l) == x) return a;
  if (alr + 1 + size(a->l) < x) {
    return get(a->r, x, alr + 1 + size(a->l));
  } else {
    return get(a->l, x, alr);
  }
}
struct Dancer {
  int id, x, tim;
};
bool cmp1(const Dancer& a, const Dancer& b) {
  if (a.tim != b.tim) return a.tim < b.tim;
  return a.x < b.x;
}
bool cmp2(const Dancer& a, const Dancer& b) { return a.x < b.x; }
int main() {
  ios::sync_with_stdio(0);
  long long n, w, h;
  cin >> n >> w >> h;
  vector<Dancer> idv;
  vector<Dancer> idh;
  for (int i = 0; i < (n); i++) {
    int g, x, t;
    cin >> g >> x >> t;
    if (g == 1) {
      idv.push_back({i, x, -x + t});
    } else {
      idh.push_back({i, x, -x + t});
    }
  }
  sort((idv).begin(), (idv).end(), cmp1);
  sort((idh).begin(), (idh).end(), cmp2);
  vector<long long> vs(idv.size());
  for (int i = 0; i < vs.size(); i++) vs[i] = idv[i].tim;
  Node* root = 0;
  for (int i = 0; i < idv.size(); i++) {
    Node* nn = new Node(idv[i].x, rand());
    nn->id = idv[i].id;
    root = merge(root, nn);
  }
  for (int i = 0; i < idh.size(); i++) {
    int f = lower_bound((vs).begin(), (vs).end(), idh[i].tim) - vs.begin();
    int l = upper_bound((vs).begin(), (vs).end(), idh[i].tim) - vs.begin();
    if (f != l) {
      if (f + 1 == l) {
        Node* v = get(root, f + 1, 0);
        swap(v->id, idh[i].id);
      } else {
        int hid = get(root, l, 0)->id;
        Node *le, *m, *m1, *ri;
        split(root, f, 0, le, m);
        split(m, l - f - 1, 0, m, ri);
        split(ri, 1, 0, m1, ri);
        Node* nn = new Node(idv[f].tim, rand());
        nn->id = idh[i].id;
        root = merge(le, nn);
        root = merge(root, m);
        root = merge(root, ri);
        idh[i].id = hid;
      }
    }
  }
  vector<pair<long long, long long> > ans(n);
  for (int i = 0; i < idh.size(); i++) {
    ans[idh[i].id].second = idh[i].x;
    ans[idh[i].id].first = w;
  }
  for (int i = 1; i <= idv.size(); i++) {
    ans[get(root, i, 0)->id].first = idv[i - 1].x;
    ans[get(root, i, 0)->id].second = h;
  }
  for (int i = 0; i < n; i++) {
    cout << ans[i].first << " " << ans[i].second << endl;
  }
  return 0;
}
