#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

int main() {
	int N,T,H,L;cin>>N>>T>>H>>L;
	vector<pair<int,int>>ps;
	for (int i = 0; i < N; ++i) {
		int t,h;cin>>t>>h;
		ps.emplace_back(t,h);
	}
	int now=0;
	int money=0;
	int ans=-1;
	while (true) {
		if (ps[now].first == 0 && ps[now].second == 0) {
			ans=now;
			break;
		}
		else {
			if (ps[now].first == 0) {
				money+=100;
				H++;
				ps[now].second--;
			}
			else {
				money+=10;
				T++;
				ps[now].first--;
			}
			if (T > L) {
				ans=now;
				break;
			}
			if (money >= 90) {
				int plus=money-90;
				if (plus > T * 10) {
					ans=now;
					break;
				}
				else {
					T-=plus/10;
					ps[now].first+=plus/10;
				}
				money=0;
			}
		}
		now=(now+1)%N;
	}
	cout<<ans+1<<endl;
	return 0;
}