Wherever the destination is, whoever we meet, let's render this song together.

On a Cartesian coordinate plane lies a rectangular stage of size w × h, represented by a rectangle with corners (0, 0), (w, 0), (w, h) and (0, h). It can be seen that no collisions will happen before one enters the stage.

On the sides of the stage stand n dancers. The i-th of them falls into one of the following groups: 

  * Vertical: stands at (xi, 0), moves in positive y direction (upwards); 
  * Horizontal: stands at (0, yi), moves in positive x direction (rightwards). 

<image>

According to choreography, the i-th dancer should stand still for the first ti milliseconds, and then start moving in the specified direction at 1 unit per millisecond, until another border is reached. It is guaranteed that no two dancers have the same group, position and waiting time at the same time.

When two dancers collide (i.e. are on the same point at some time when both of them are moving), they immediately exchange their moving directions and go on.

<image>

Dancers stop when a border of the stage is reached. Find out every dancer's stopping position.

Input

The first line of input contains three space-separated positive integers n, w and h (1 ≤ n ≤ 100 000, 2 ≤ w, h ≤ 100 000) — the number of dancers and the width and height of the stage, respectively.

The following n lines each describes a dancer: the i-th among them contains three space-separated integers gi, pi, and ti (1 ≤ gi ≤ 2, 1 ≤ pi ≤ 99 999, 0 ≤ ti ≤ 100 000), describing a dancer's group gi (gi = 1 — vertical, gi = 2 — horizontal), position, and waiting time. If gi = 1 then pi = xi; otherwise pi = yi. It's guaranteed that 1 ≤ xi ≤ w - 1 and 1 ≤ yi ≤ h - 1. It is guaranteed that no two dancers have the same group, position and waiting time at the same time.

Output

Output n lines, the i-th of which contains two space-separated integers (xi, yi) — the stopping position of the i-th dancer in the input.

Examples

Input

8 10 8
1 1 10
1 4 13
1 7 1
1 8 2
2 2 0
2 5 14
2 6 0
2 6 1


Output

4 8
10 5
8 8
10 6
10 2
1 8
7 8
10 6


Input

3 2 3
1 1 2
2 1 1
1 1 5


Output

1 3
2 1
1 3

Note

The first example corresponds to the initial setup in the legend, and the tracks of dancers are marked with different colours in the following figure.

<image>

In the second example, no dancers collide.
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashMap;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;
import java.util.Map;
import java.util.Map.Entry;
import java.io.BufferedReader;
import java.util.Collections;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author liymsheep
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n, w, h;
            n = in.nextInt();
            w = in.nextInt();
            h = in.nextInt();

            Map<Integer, ArrayList<TaskB.Node>> allNodes = new HashMap<>();
            for (int i = 0; i < n; ++i) {
                TaskB.Node node = new TaskB.Node(in.nextInt(), in.nextInt(), in.nextInt(), i);
                if (!allNodes.containsKey(node.key())) {
                    allNodes.put(node.key(), new ArrayList<>());
                }
                allNodes.get(node.key()).add(node);
            }

            int[] x = new int[n];
            int[] y = new int[n];
            for (Map.Entry<Integer, ArrayList<TaskB.Node>> entry : allNodes.entrySet()) {
                ArrayList<TaskB.Node> nodes = entry.getValue();
                Collections.sort(nodes);
                int[] ids = new int[nodes.size()];
                int count = 0;
                for (int i = 0; i < nodes.size(); ++i) {
                    if (nodes.get(i).dir == 2) {
                        ids[count++] = nodes.get(i).id;
                    }
                }
                for (int i = 0; i < nodes.size(); ++i) {
                    if (nodes.get(i).dir == 1) {
                        ids[count++] = nodes.get(i).id;
                    }
                }

                assert (count == nodes.size());
                for (int i = 0; i < nodes.size(); ++i) {
                    int nx = 0, ny = 0;
                    if (nodes.get(i).dir == 1) {
                        nx = nodes.get(i).pos;
                        ny = h;
                    } else {
                        nx = w;
                        ny = nodes.get(i).pos;
                    }
                    x[ids[i]] = nx;
                    y[ids[i]] = ny;
                }
            }
            for (int i = 0; i < n; ++i) {
                out.println(x[i] + " " + y[i]);
            }
        }

        static class Node implements Comparable<TaskB.Node> {
            int dir;
            int pos;
            int time;
            int id;

            Node(int dir, int pos, int time, int id) {
                this.dir = dir;
                this.pos = pos;
                this.time = time;
                this.id = id;
            }


            public int compareTo(TaskB.Node o) {
                if (dir != o.dir) return dir - o.dir;
                if (pos != o.pos) {
                    if (dir == 1) return pos - o.pos;
                    return o.pos - pos;
                }
                return time - o.time;
            }

            public int key() {
                return pos - time;
            }

        }

    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (Exception e) {
                    throw new UnknownError();
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}

