// Задача "Перекресток"
// Вторая командная Интернет-олимпиада сезона 2010-2011, базовый уровень.
// Автор задачи: Лидия Перовская.
// Автор решения: Антон Ахи, akhi@rain.ifmo.ru

import java.io.*;
import java.util.*;
import java.math.*;

public class carrefour_aa {
	public static void main(String[] args) {
		new carrefour_aa().run();
	}

	BufferedReader br;
	StringTokenizer st;
	PrintWriter out;
	boolean eof = false;

	public void run() {
		Locale.setDefault(Locale.US);
		try {
			br = new BufferedReader(new FileReader(FNAME + ".in"));
			out = new PrintWriter(FNAME + ".out");
			solve();
			out.close();
		} catch (Throwable e) {
			e.printStackTrace();
			System.exit(566);
		}
	}

	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				eof = true;
				return "0";
			}
		}
		return st.nextToken();
	}

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

	void myAssert(boolean u, String message) {
		if (!u) {
			throw new Error("Assertion failed!!! " + message);
		}
	}

	int inBounds(int x, int l, int r, String name) {
		myAssert(l <= x && x <= r, name + " is not in bounds: " + x
				+ " not in [" + l + ", " + r + "]");
		return x;
	}

	String FNAME = "carrefour";

	private void solve() throws IOException {
		int n = inBounds(nextInt(), 1, 100, "n");
		int m1 = inBounds(nextInt(), 1, 4, "a") - 1;
		int m2 = inBounds(nextInt(), 1, 4, "b") - 1;
		myAssert(m1 != m2, "Ends of main road are equal");
		@SuppressWarnings("unchecked")
		ArrayList<Car>[] a = new ArrayList[4];
		for (int i = 0; i < a.length; i++) {
			a[i] = new ArrayList<Car>();
		}
		for (int i = 0; i < n; i++) {
			Car c = new Car(inBounds(nextInt(), 1, 4, "d_" + (i + 1)) - 1,
					inBounds(nextInt(), 1, 100, "t_" + (i + 1)), i);
			a[c.d].add(c);
		}
		for (int i = 0; i < a.length; i++) {
			Collections.sort(a[i]);
		}
		for (int i = 0; i < a.length; i++) {
			for (int j = 1; j < a[i].size(); j++) {
				myAssert(a[i].get(j).t != a[i].get(j - 1).t,
						"Cars " + (a[i].get(j).n + 1) + " "
								+ (a[i].get(j - 1).n + 1)
								+ " arrive simultaniously");
			}
		}
		int[] t = new int[n];
		int[] c = new int[4];
		c[m1] = 2;
		c[m2] = 2;
		for (int i = 0; i < c.length; i++) {
			if (c[i] == c[(i + 1) % 4]) {
				c[i]++;
			}
		}
		int[] k = new int[4];
		for (int time = 1; time <= 1000; time++) {
			boolean found = false;
			for (int prior = 3; prior >= 0 && !found; prior--) {
				for (int i = 0; i < k.length; i++) {
					if (c[i] == prior && k[i] < a[i].size()
							&& a[i].get(k[i]).t <= time) {
						t[a[i].get(k[i]++).n] = time;
						found = true;
					}
				}
			}
		}
		for (int i = 0; i < t.length; i++) {
			out.println(t[i]);
		}
	}

	class Car implements Comparable<Car> {
		public Car(int d2, int t2, int i) {
			d = d2;
			t = t2;
			n = i;
		}

		int d, t, n;

		@Override
		public int compareTo(Car c) {
			return t - c.t;
		}
	}
}
