#include <bits/stdc++.h>
using namespace std;
int main(int argc, char **argv) {
  int n, w, h;
  cin >> n >> w >> h;
  vector<vector<pair<int, pair<int, int>>>> finish(400000);
  vector<vector<pair<int, int>>> start(400000);
  vector<pair<int, int>> result(n);
  for (int i = 0; i < n; ++i) {
    int g, p, t, start_x, end_x, start_y, end_y, group_id, start_position,
        end_position;
    cin >> g >> p >> t;
    if (g == 2) {
      end_y = start_y = p + 100000;
      start_x = 100000 - t;
      end_x = 100000 + w;
    } else {
      start_x = end_x = p + 100000;
      start_y = 100000 - t;
      end_y = 100000 + h;
    }
    group_id = start_x + start_y;
    start_position = start_x - start_y;
    end_position = end_x - end_y;
    start[group_id].push_back(make_pair(start_position, i));
    finish[group_id].push_back(
        make_pair(end_position, make_pair(end_x, end_y)));
  }
  for (int i = 0; i < 400000; ++i) {
    if (start[i].empty()) {
      continue;
    }
    sort(start[i].begin(), start[i].end());
    sort(finish[i].begin(), finish[i].end());
    for (int j = 0; j < start[i].size(); ++j) {
      result[start[i][j].second] = finish[i][j].second;
    }
  }
  for (int i = 0; i < n; ++i) {
    cout << result[i].first - 100000 << ' ' << result[i].second - 100000
         << endl;
  }
  return 0;
}
