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

public class game_ats implements Runnable {
	public static void main(String[] args) {
		new Thread(new game_ats()).start();
	}

	BufferedReader br;
	StringTokenizer in;
	PrintWriter out;

	public String nextToken() throws IOException {
		while (in == null || !in.hasMoreTokens()) {
			in = new StringTokenizer(br.readLine());
		}
		return in.nextToken();
	}

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

	public long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	public double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	public void solve() throws IOException {
		int n = nextInt();
		int m = nextInt();
		int k = nextInt();
		int r = nextInt();

		assert (1 <= n && n <= (int) 1e5);
		assert (1 <= m && m <= (int) 1e5);
		assert (1 <= k && k <= (int) 1e5);
		assert (Math.abs(r) <= 1000 && Math.abs(r) <= m);

		int curMin = r;
		int curMax = r;

		int petya = -1;
		int vasya = -1;

		for (int i = 1; i <= n; i++) {
			int a = nextInt();
			int b = nextInt();
			assert ((a == 0 || a == 1) && (b == 0 || b == 1));
			if (a + b == 1) {
				if (a == 1) {
					curMin--;
					curMax--;
				} else {
					curMin++;
					curMax++;
				}
			} else if (a + b == 2) {
				curMin -= k;
				curMax += k;
			}
			if (curMin < -m && vasya == -1) {
				vasya = i;
			}
			if (curMax > m && petya == -1) {
				petya = i;
			}
		}
		out.println(petya + " " + vasya);
	}

	public void run() {
		try {
			Locale.setDefault(Locale.US);
			br = new BufferedReader(new FileReader("game.in"));
			out = new PrintWriter("game.out");

			solve();

			out.close();
			br.close();
		} catch (IOException e) {
			e.printStackTrace();
			System.exit(1);
		}
	}
}
