#include <bits/stdc++.h>
using namespace std;
class UnionFind {
 private:
  vector<int> p, rank;

 public:
  UnionFind(int N) {
    rank.assign(N + 1, 0);
    p.assign(N + 1, 0);
    for (int i = 0; i <= N; i++) p[i] = i;
  }
  int findSet(int i) { return (p[i] == i) ? i : (p[i] = findSet(p[i])); }
  bool isSameSet(int i, int j) { return findSet(i) == findSet(j); }
  void unionSet(int i, int j) {
    if (!isSameSet(i, j)) {
      int x = findSet(i), y = findSet(j);
      if (rank[x] > rank[y])
        p[y] = x;
      else {
        p[x] = y;
        if (rank[x] == rank[y]) rank[y]++;
      }
    }
  }
};
pair<int, int> ans[100010];
int cd[2][2 * 100010] = {{0}, {0}};
int g[100010], p[100010], t[100010], par[2][100010 * 2], point[100010] = {0};
const int off = 100010;
vector<int> mem[100010];
bool compr(int i, int j) {
  if (g[i] != g[j]) return (g[i] < g[j]);
  if (g[i]) return p[i] < p[j];
  return p[i] > p[j];
}
int main() {
  int n, w, h;
  scanf("%d %d %d", &n, &w, &h);
  UnionFind a(n);
  for (int i = 0; i < n; ++i) {
    scanf("%d %d %d", g + i, p + i, t + i);
    --g[i];
    g[i] ^= 1;
    int vpos = p[i] - t[i] + off;
    int *mark = &cd[g[i]][vpos];
    if (*mark) {
      a.unionSet(par[g[i]][vpos], i);
    } else {
      *mark = 1;
      par[g[i]][vpos] = i;
    }
  }
  for (int i = 0; i < n; ++i) {
    int vpos = p[i] - t[i] + off;
    if (cd[g[i] ^ 1][vpos]) a.unionSet(i, par[g[i] ^ 1][vpos]);
  }
  for (int i = 0; i < n; ++i) {
    mem[a.findSet(i)].push_back(i);
  }
  for (int i = 0; i < n; ++i) {
    int pp = a.findSet(i);
    if (i != pp) continue;
    sort(mem[pp].begin(), mem[pp].end(), compr);
    for (int j = 0; j < mem[pp].size(); ++j) {
      if (g[mem[pp][j]] == 1) {
        point[i] = j;
        break;
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    int ptr = point[i] - 1;
    for (int j = mem[i].size() - 1; j >= 0; --j) {
      if (ptr < 0) ptr = mem[i].size() - 1;
      int idx = mem[i][ptr];
      ans[mem[i][j]] = (g[idx] ? make_pair(p[idx], h) : make_pair(w, p[idx]));
      ptr--;
    }
  }
  for (int i = 0; i < n; ++i) printf("%d %d\n", ans[i].first, ans[i].second);
}
