#include<cstdio>
 
#define rep(i,n) for(int i=0;i<(n);i++)
 
using namespace std;
 
int main(){
    int n,T,H,L; scanf("%d%d%d%d",&n,&T,&H,&L);
    int t[100],h[100];
    rep(i,n) scanf("%d%d",t+i,h+i);
 
    int yen=0;
    while(1){
        rep(i,n){
            if(t[i]>0){
                t[i]--;
                T++;
                yen+=10;
                if(T>L){ printf("%d\n",i+1); return 0; }
            if(yen==90){
                int back=yen-90;
                if(T<back/10){ printf("%d\n",i+1); return 0; }
                T-=back/10;
                //t[i]+=back/10;
                yen=0;
            }
            }
            else if(h[i]>0){
                h[i]--;
                H++;
                yen+=100;
            //if(yen>=90){
                int back=yen-90;
                if(T<back/10){ printf("%d\n",i+1); return 0; }
                T-=back/10;
                t[i]+=back/10;
                yen=0;
            //}
            }
            else{
                printf("%d\n",i+1);
                return 0;
            }
        }
    }
}