import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.typecons;

void main() {
	auto input = map!(to!int)(readln.split);
	int N = input[0], T = input[1], H = input[2], L = input[3];
	Tuple!(int, int)[] data;
	foreach (i; 0..N) {
		input = map!(to!int)(readln.split);
		auto t = input[0], h = input[1];
		data ~= tuple(t, h);
	}
	int i = 0;
	int remain = 0;
	while (true) {
		if (data[i][0] > 0) {
			T++;
			data[i][0]--;
			remain += 10;
			if (T > L){
				break;
			 }
		} else if(data[i][1] > 0) {
			H++;
			data[i][1]--;
			remain += 100;
		} else {
			break;
		}
		if (remain >= 90) {
			remain -= 90;
			if (remain <= 10 * T) {
				data[i][0] += remain / 10;
				T -= remain / 10;
			} else if ((remain % 100) <= 10 * T && remain / 100 <= H) {
				data[i][1] += remain / 100;
				H -= remain / 100;
				remain %= 100;
				data[i][0] += remain / 10;
				T -= remain / 10;
			} else {
				break;
			}
			remain = 0;
		}
		i++;
		if (i == N) i = 0;
	}
	writeln(i+1);
}