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 static java.lang.Math.min;
import static java.util.Collections.*;

import java.util.*;

public class B {

	public B () {
		int N = sc.nextInt(), W = sc.nextInt(), H = sc.nextInt();
		int [][] D = sc.nextInts(N);

		int [] Q = new int [N];
		for (int i : rep(N))
			Q[i] = D[i][0];

		@SuppressWarnings("unchecked") Map<Integer, ArrayList<int[]>>[] G = new Map[2];
		for (int g : rep(2)) G[g] = new TreeMap<>();

		for (int i : rep(N)) {
			int [] d = D[i];
			int j = d[0] -1, k = d[1] - d[2]; d[0] = i;
			if (!G[j].containsKey(k))
				G[j].put(k, new ArrayList<int[]>());
			G[j].get(k).add(d);
		}

		for (int g : rep(2))
			for (ArrayList<int[]> s : G[g].values())
				sort(s, by(1));

		int [][] res = new int [N][];
		for (int g : rep(2))
			for (int k : G[g].keySet()) {
				if (!G[1-g].containsKey(k))
					continue;
				ArrayList<int []> s = G[g].get(k), t = G[1-g].get(k);
				for (int i : rep(s.size()))  {
					int K = s.size() - i - 1, L = t.size(), j = s.get(i)[0];
					K = min(K, L); L = min(K+1, L);
					if (g == 0) {
						if (K == L) res[j] = new int [] { s.get(i+K)[1], H };
						else res[j] = new int [] { W, t.get(L-1)[1] };
					} else if (K == L) res[j] = new int [] { W, s.get(i+K)[1] };
					else res[j] = new int [] { t.get(L-1)[1], H };
				}
			}

		for (int i : rep(N)) {
			if (res[i] == null)
				if (Q[i] == 1)
					res[i] = new int [] { D[i][1], H };
				else
					res[i] = new int [] { W, D[i][1] };
			print(res[i]);
		}

	}

	private static Comparator<int[]> by(final int ... J) { return new Comparator<int[]>() { public int compare(int[] x, int[] y) { for (int i : J) if (x[i] != y[i]) return x[i] - y[i]; return 0; }}; }
	private static int [] rep(int N) { return rep(0, N); }
	private static int [] rep(int S, int T) { if (T <= S) return new int [0]; int [] res = new int [T-S]; for (int i = S; i < T; ++i) res[i-S] = i; return res; }
	////////////////////////////////////////////////////////////////////////////////////
	private final static IOUtils.MyScanner sc = new IOUtils.MyScanner();
	private static void print (Object o, Object ... A) { IOUtils.print(o, A); }
	private static class IOUtils {
		public static class MyScanner {
			public String next() { newLine(); return line[index++]; }
			public int nextInt() { return Integer.parseInt(next()); }
			public String nextLine() { line = null; return readLine(); }
			public String [] nextStrings() { return split(nextLine()); }
			public int [] nextInts() {
				String [] L = nextStrings();
				int [] res = new int [L.length];
				for (int i = 0; i < L.length; ++i)
					res[i] = Integer.parseInt(L[i]);
				return res;
			}
			public int [][] nextInts (int N) {
				int [][] res = new int [N][];
				for (int i = 0; i < N; ++i)
					res[i] = nextInts();
				return res;
			}
			//////////////////////////////////////////////
			private boolean eol() { return index == line.length; }
			private String readLine() {
				try {
					return r.readLine();
				} catch (Exception e) {
					throw new Error (e);
				}
			}
			private final java.io.BufferedReader r;
			private MyScanner () { this(new java.io.BufferedReader(new java.io.InputStreamReader(System.in))); }
			private MyScanner (java.io.BufferedReader r) {
				try {
					this.r = r;
					while (!r.ready())
						Thread.sleep(1);
					start();
				} catch (Exception e) {
					throw new Error(e);
				}
			}
			private String [] line;
			private int index;
			private void newLine() {
				if (line == null || eol()) {
					line = split(readLine());
					index = 0;
				}
			}
			private String [] split(String s) { return s.length() > 0 ? s.split(" ") : new String [0]; }
		}
		private static String build(Object o, Object ... A) { return buildDelim(" ", o, A); }
		private static String buildDelim(String delim, Object o, Object ... A) {
			StringBuilder b = new StringBuilder();
			append(b, o, delim);
			for (Object p : A)
				append(b, p, delim);
			return b.substring(delim.length());
		}
		//////////////////////////////////////////////////////////////////////////////////
		private static void start() { if (t == 0) t = millis(); }
		private static void append(StringBuilder b, Object o, String delim) {
			if (o.getClass().isArray()) {
				int len = java.lang.reflect.Array.getLength(o);
				for (int i = 0; i < len; ++i)
					append(b, java.lang.reflect.Array.get(o, i), delim);
			} else if (o instanceof Iterable<?>)
				for (Object p : (Iterable<?>) o)
					append(b, p, delim);
			else {
				if (o instanceof Double)
					o = new java.text.DecimalFormat("#.############").format(o);
				b.append(delim).append(o);
			}
		}
		private static java.io.PrintWriter pw = new java.io.PrintWriter(System.out);
		private static void print(Object o, Object ... A) { pw.println(build(o, A)); }
		private static void err(Object o, Object ... A) { System.err.println(build(o, A)); }
		private static void exit() {
			IOUtils.pw.close();
			System.out.flush();
			err("------------------");
			err(IOUtils.time());
			System.exit(0);
		}
		private static long t;
		private static long millis() { return System.currentTimeMillis(); }
		private static String time() { return "Time: " + (millis() - t) / 1000.0; }
	}
	public static void main (String[] args) { new B(); IOUtils.exit(); }
}
