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.*;
import java.util.*;

import static java.math.BigDecimal.valueOf;

public class Solution {
    static MyScanner sc;
    private static PrintWriter out;
    static long M2 = 1_000_000_000L + 7;

    public static void main(String[] s) throws Exception {
        StringBuilder stringBuilder = new StringBuilder();

//        stringBuilder.append("8 10 8\n" +
//                "1 1 10\n" +
//                "1 4 13\n" +
//                "1 7 1\n" +
//                "1 8 2\n" +
//                "2 2 0\n" +
//                "2 5 14\n" +
//                "2 6 0\n" +
//                "2 6 1");

//        stringBuilder.append("100000 100000 100000 ");
//        for (int i = 0; i < 500000; i++) {
//            stringBuilder.append("1 " + (i + 1) + " " + (i + 1) + " ");
//            stringBuilder.append("2 " + (i + 1) + " " + (i + 1) + " ");
//        }

        if (stringBuilder.length() == 0) {
            sc = new MyScanner(System.in);
        } else {
            sc = new MyScanner(new BufferedReader(new StringReader(stringBuilder.toString())));
        }


        out = new PrintWriter(new OutputStreamWriter(System.out));
        initData();
        solve();
//        out.println(time);
        out.flush();
    }


    private static void initData() {

    }

    static long time;

    private static void solve() throws IOException {
        int n = sc.nextInt();
        int w = sc.nextInt();
        int h = sc.nextInt();

        int[][] data = new int[n][2];

        Map<Integer, List<Integer>> hor = new HashMap<>();
        Map<Integer, List<Integer>> ver = new HashMap<>();


        for (int s = 0; s < n; s++) {
            int x = sc.nextInt();
            int cc = sc.nextInt();
            int time = sc.nextInt();

            if (x == 1) {
                data[s][0] = cc;
                data[s][1] = h;
                ver.computeIfAbsent(cc - time, de -> new ArrayList<>()).add(s);
            } else {
                data[s][0] = w;
                data[s][1] = cc;
                hor.computeIfAbsent(cc - time, de -> new ArrayList<>()).add(s);
            }

        }


        for (Map.Entry<Integer, List<Integer>> d1 : ver.entrySet()) {
            List<Integer> other = hor.get(d1.getKey());
            if (other == null) continue;
            List<Integer> our = d1.getValue();
            our.sort(Comparator.comparingInt(t -> data[t][0]));
            other.sort(Comparator.comparingInt(t -> -data[t][1]));

            LinkedList<int[]> dd = new LinkedList<>();
            for (int s : our) {
                dd.add(new int[]{data[s][0], data[s][1]});
            }
            for (int s : other) {
                dd.add(new int[]{data[s][0], data[s][1]});
            }
            for (int s : other) {
                data[s] = dd.removeFirst();
            }
            for (int s : our) {
                data[s] = dd.removeFirst();
            }


        }

        for (int i = 0; i < n; i++) {
            out.println(data[i][0] + " " + data[i][1]);
        }
    }


    private static void solveT() throws IOException {
        int t = sc.nextInt();
        while (t-- > 0) {
            solve();
        }
    }

    private static long gcd(long l, long l1) {
        if (l > l1) return gcd(l1, l);
        if (l == 0) return l1;
        return gcd(l1 % l, l);
    }

    private static long pow(long a, long b, long m) {
        if (b == 0) return 1;
        if (b == 1) return a;
        long pp = pow(a, b / 2, m);
        pp *= pp;
        pp %= m;
        return (pp * (b % 2 == 0 ? 1 : a)) % m;
    }


    static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        MyScanner(BufferedReader br) {
            this.br = br;
        }

        public MyScanner(InputStream in) {
            this(new BufferedReader(new InputStreamReader(in)));
        }

        void findToken() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }

        String next() {
            findToken();
            return st.nextToken();
        }

        Integer[] nab(int n) {
            Integer[] k = new Integer[n];
            for (int i = 0; i < n; i++) {
                k[i] = sc.fi();
            }
            return k;
        }

        int[] na(int n) {
            int[] k = new int[n];
            for (int i = 0; i < n; i++) {
                k[i] = sc.fi();
            }
            return k;
        }

        long[] nl(int n) {
            long[] k = new long[n];
            for (int i = 0; i < n; i++) {
                k[i] = sc.nextLong();
            }
            return k;
        }

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

        int fi() {
            String t = next();
            int cur = 0;
            boolean n = t.charAt(0) == '-';
            for (int a = n ? 1 : 0; a < t.length(); a++) {
                cur = cur * 10 + t.charAt(a) - '0';
            }
            return n ? -cur : cur;
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }


}