#include <bits/stdc++.h>
int main() {
  int n, dim[2];
  std::cin >> n >> dim[0] >> dim[1];
  int fin[n][2];
  std::vector<std::pair<int, std::pair<int, int> > > cat[300000];
  std::vector<std::vector<int> > len(300000, std::vector<int>(2, 0));
  for (int i = 0; i < n; i++) {
    int g, p, t;
    std::cin >> g >> p >> t;
    g = 2 - g;
    cat[p - t + 100000].push_back({g, {(2 * g - 1) * p, i}});
    len[p - t + 100000][g]++;
    fin[i][g] = dim[g];
    fin[i][1 - g] = p;
  }
  for (int i = 0; i < 300000; i++) std::sort(cat[i].begin(), cat[i].end());
  int ans[n];
  for (int i = 0; i < 300000; i++) {
    for (int j = 0; j < cat[i].size(); j++) {
      ans[cat[i][j].second.second] =
          cat[i][(j +
                  (2 * (len[i][0] < len[i][1]) - 1) *
                      std::min(len[i][0], len[i][1]) +
                  cat[i].size()) %
                 cat[i].size()]
              .second.second;
    }
  }
  for (int i = 0; i < n; i++) {
    std::cout << fin[ans[i]][0] << " " << fin[ans[i]][1] << std::endl;
  }
  return 0;
}
