#include <bits/stdc++.h>
using namespace std;
const int maxn = 202000;
const int mm = 101000;
int n, ans[maxn];
int W, H;
vector<int> g[maxn], g2[maxn];
struct Node {
  int first, second, w, id;
} a[maxn];
bool cmp1(const Node a, const Node b) {
  return a.first < b.first || (a.first == b.first && a.second < b.second);
}
bool cmp2(const Node a, const Node b) { return a.id < b.id; }
void init() {
  int first, second;
  scanf("%d%d%d", &n, &W, &H);
  for (int i = (1); i <= (n); ++i) {
    scanf("%d%d%d", &first, &second, &a[i].w);
    if (first == 1) {
      a[i].first = second;
    } else {
      a[i].second = second;
    }
    a[i].id = i;
  }
  sort(a + 1, a + n + 1, cmp1);
  for (int i = (1); i <= (n); ++i)
    if (a[i].first == 0) {
      g[a[i].second - a[i].w + mm].push_back(a[i].id);
    } else {
      g2[a[i].first - a[i].w + mm].push_back(a[i].id);
    }
}
void work() {
  int first;
  for (int i = (0); i <= (maxn - 1); ++i) {
    int len1 = g[i].size(), len2 = g2[i].size();
    if (!len1 && !len2) continue;
    for (int j = (len2 - 1); j >= (0); --j) g[i].push_back(g2[i][j]);
    int k = 0;
    for (int j = (len2 - 1); j >= (0); --j) ans[g2[i][j]] = g[i][k++];
    for (int j = (0); j <= (len1 - 1); ++j) ans[g[i][j]] = g[i][k++];
  }
  for (int i = (1); i <= (n); ++i)
    if (a[i].first == 0) {
      a[i].first = W;
    } else {
      a[i].second = H;
    }
  sort(a + 1, a + n + 1, cmp2);
  for (int i = (1); i <= (n); ++i) {
    first = ans[i];
    printf("%d %d\n", a[first].first, a[first].second);
  }
}
int main() {
  init();
  work();
  return 0;
}
