#include <bits/stdc++.h>
static const int MAXN = 100004;
static const int MAXW = 100003;
static const int MAXT = 100002;
int n, w, h;
int g[MAXN], p[MAXN], t[MAXN];
std::vector<int> s[MAXW + MAXT];
int ans_x[MAXN], ans_y[MAXN];
int main() {
  scanf("%d%d%d", &n, &w, &h);
  for (int i = 0; i < n; ++i) {
    scanf("%d%d%d", &g[i], &p[i], &t[i]);
    s[p[i] - t[i] + MAXT].push_back(i);
  }
  std::vector<int> xs, ys;
  for (int i = 0; i < MAXW + MAXT; ++i)
    if (!s[i].empty()) {
      for (int u : s[i]) {
        if (g[u] == 1)
          xs.push_back(p[u]);
        else
          ys.push_back(p[u]);
      }
      std::sort(xs.begin(), xs.end());
      std::sort(ys.begin(), ys.end());
      std::sort(s[i].begin(), s[i].end(), [](int u, int v) {
        if (g[u] != g[v])
          return (g[u] == 2);
        else
          return (g[u] == 2 ? p[u] > p[v] : p[u] < p[v]);
      });
      for (int j = 0; j < xs.size(); ++j) {
        ans_x[s[i][j]] = xs[j];
        ans_y[s[i][j]] = h;
      }
      for (int j = 0; j < ys.size(); ++j) {
        ans_x[s[i][j + xs.size()]] = w;
        ans_y[s[i][j + xs.size()]] = ys[ys.size() - j - 1];
      }
      xs.clear();
      ys.clear();
    }
  for (int i = 0; i < n; ++i) printf("%d %d\n", ans_x[i], ans_y[i]);
  return 0;
}
