#include <bits/stdc++.h>
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, -1, 0, 1};
template <class T>
void inputVector(vector<T> &v, int n) {
  v.resize(n);
  for (int i = 0; i < v.size(); i++) cin >> v[i];
}
int n, w, h;
class Person {
 public:
  int x, y, g, id;
  int gx, gy;
  Person() {}
  Person(int x, int y, int g, int id) {
    this->x = x;
    this->y = y;
    this->g = g;
    if (g == 1) {
      gx = x;
      gy = h;
    } else {
      gx = w;
      gy = y;
    }
    this->id = id;
  }
  int val() { return x + y; }
  bool operator<(const Person &a) const {
    if (x + y != a.x + a.y) return x + y < a.x + a.y;
    return x >= a.x;
  }
};
vector<Person> persons;
signed main() {
  cin >> n >> w >> h;
  for (int i = 0; i < (n); i++) {
    int g, p, t;
    scanf("%d %d %d", &g, &p, &t);
    if (g == 1) {
      persons.push_back(Person(p, -t, g, i));
    } else {
      persons.push_back(Person(-t, p, g, i));
    }
  }
  sort((persons).begin(), (persons).end());
  int pt1 = 0;
  while (pt1 < n) {
    int pt2 = pt1;
    int vcnt = 0;
    while (pt2 < n) {
      if (persons[pt1].val() == persons[pt2].val()) {
        if (persons[pt2].g == 1) vcnt++;
        pt2++;
      } else
        break;
    }
    pt2--;
    int N = pt2 - pt1 + 1;
    vector<pair<int, int>> pr;
    for (int i = (pt1); i <= (pt2); i++)
      pr.push_back(make_pair(persons[i].gx, persons[i].gy));
    for (int i = (pt1); i <= (pt2); i++) {
      persons[i].gx = pr[(i - pt1 + vcnt) % N].first;
      persons[i].gy = pr[(i - pt1 + vcnt) % N].second;
    }
    pt1 = pt2 + 1;
  }
  sort((persons).begin(), (persons).end(),
       [&](Person &a, Person &b) { return a.id < b.id; });
  for (int i = 0; i < (n); i++) {
    printf("%d %d\n", persons[i].gx, persons[i].gy);
  }
  return 0;
}
