#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, w, h, to[N], cnt = 0;
struct people {
  int x, y, id, op;
};
struct answer {
  int x, y;
} ans[N];
vector<people> a, b;
bool cmp1(people p1, people p2) { return p1.y < p2.y; }
bool cmp2(people p1, people p2) { return p1.x < p2.x; }
namespace sub1 {
void solve() {
  for (int i = 0; i < b.size(); ++i) {
    int x1 = b[i].x, y1 = b[i].y;
    int now = b[i].id;
    for (int j = 0; j < a.size(); ++j) {
      int x2 = a[j].x, y2 = a[j].y, nxt = a[j].id;
      if (abs(x1 - x2) == abs(y1 - y2)) {
        swap(ans[to[now]], ans[to[nxt]]);
        swap(to[now], to[nxt]);
      }
    }
  }
  for (int i = 1; i <= n; ++i) printf("%d %d\n", ans[i].x, ans[i].y);
}
}  // namespace sub1
map<int, int> mp;
vector<people> c[N];
namespace moonpie {
vector<answer> at;
answer res[N];
bool cmpa(answer a1, answer a2) {
  if (a1.x != a2.x)
    return a1.x < a2.x;
  else
    return a1.y > a2.y;
}
void solve() {
  for (int i = 1; i <= cnt; ++i) {
    sort(c[i].begin(), c[i].end(), cmp2);
    at.clear();
    for (int j = 0; j < c[i].size(); ++j) at.push_back(ans[c[i][j].id]);
    sort(at.begin(), at.end(), cmpa);
    for (int j = 0; j < c[i].size(); ++j) res[c[i][j].id] = at[j];
  }
  for (int i = 1; i <= n; ++i) printf("%d %d\n", res[i].x, res[i].y);
}
}  // namespace moonpie
int main() {
  cin >> n >> w >> h;
  cnt = 0;
  for (int x, y, op, p, t, i = 1; i <= n; ++i) {
    scanf("%d%d%d", &op, &p, &t);
    if (op == 1)
      op = 2;
    else
      op = 1;
    if (op == 1) {
      x = -t;
      y = p;
      ans[i] = answer{w, p};
    } else {
      x = p;
      y = -t;
      ans[i] = answer{p, h};
    }
    if (!mp[y + x]) mp[y + x] = ++cnt;
    c[mp[y + x]].push_back(people{x, y, i, op});
  }
  moonpie::solve();
  return 0;
}
