class VendingMachine {// ?????????
	// define
	private enum storageType{
		STORAGETYPE_10YEN,
		STORAGETYPE_100YEN,
		STORAGETYPE_NUM
	};
	private const int CAPA_INFINITE = 1 << 30; // 100???????????¬?????????????°?????????£???
	public  const int JUICEVALUE    = 90;      // ??¨??????private?????????????????\????????????????????¬????????????????????????????????????????????????
	
	public enum coin{
		COIN_10YEN,
		COIN_100YEN
	}

	class Storage { // ??¬??¨?????\??????????????¨?????? ??????????????????????????§private?????????????????????
		int capacity_;
		int currentCount_; // ????????£???????????¬??¨????????°
		public Storage(int c, int initNum) {
			capacity_ = c;
			currentCount_ = initNum;
		} 
		
		public enum StorageErrType{ // storage????????´
			ERR_NONE,
			ERR_CAPAINVALID
		};
		
		public StorageErrType setCoin(int change) { // ??¬??¨???????????????????????????????????? ?????¶????¨??????¨?????´????????????
			currentCount_ += change;
			StorageErrType ret = StorageErrType.ERR_NONE;
			if ((currentCount_ < 0) || (capacity_ < currentCount_)) { // ?????????????¶????????????£??????storage?????????????????????
				ret = StorageErrType.ERR_CAPAINVALID;
			}
			return ret;
		}
	}
	
	// member
	Storage[] coinStorage;
	int       insertValue;
	
	// method
	public VendingMachine(int default10YenCount, int default100YenCount, int capa) {
		coinStorage = new Storage[(int)storageType.STORAGETYPE_NUM];
		coinStorage[(int)storageType.STORAGETYPE_10YEN ] = new Storage(capa, default10YenCount);
		coinStorage[(int)storageType.STORAGETYPE_100YEN] = new Storage(CAPA_INFINITE, default100YenCount);
		
		insertValue = 0;
	}
	
	public bool insertCoin(coin c, out int changeCoin) { // ????§????????????\???1????????? ??????????????¶??£?£?????????´??????false?????????
		Storage.StorageErrType storageErrCode = Storage.StorageErrType.ERR_NONE;
		switch (c) { // storage????????????
		  case coin.COIN_10YEN:
			storageErrCode |= coinStorage[(int)storageType.STORAGETYPE_10YEN].setCoin(1);
			insertValue += 10;
			break;
		  case coin.COIN_100YEN:
			coinStorage[(int)storageType.STORAGETYPE_100YEN].setCoin(1); // 100???????????¬???????????°????????¬?????§??????????????????
			insertValue += 100;
			break;
		  default: // ???????????????
			break;
		}

		if (JUICEVALUE <= insertValue) { //?????\???????????¬??????
			int change = insertValue - JUICEVALUE; // ?????????
			storageErrCode |= coinStorage[(int)storageType.STORAGETYPE_10YEN].setCoin(-1 * change / 10); // storage???????????£??????????????????
			changeCoin = change / 10;
			insertValue = 0;
		}
		else {
			changeCoin = 0;
		}
		
		return storageErrCode == Storage.StorageErrType.ERR_NONE;
	}
};

class Member_2DR { // ???????????????????¬????????????????????????????
	//member
	int count10Yen;
	int count100Yen;
	
	public Member_2DR(int c10, int c100) {
		count10Yen  = c10;
		count100Yen = c100;
	}
	
	public bool insertCoin(VendingMachine vm) {// true????????????????¶??¶????false??????????????§??????
		bool ret = true;
		if (ret && (count10Yen == 0) && (count100Yen == 0)) { //?????????????????????
			ret = false;
		}
		
		if (ret) {
			int change10Yen = 0;
			if (count10Yen > 0 ) {
				ret = vm.insertCoin(VendingMachine.coin.COIN_10YEN, out change10Yen);
				--count10Yen;
			}
			else if (count100Yen > 0) {
				ret = vm.insertCoin(VendingMachine.coin.COIN_100YEN, out change10Yen);
				--count100Yen;
			}
			count10Yen += change10Yen;
			// ?????????????????¨???????????????????????§????????£?????????????????????????????§?????????????????????????????????
		}
		//System.Console.WriteLine("count10Yen = {0} count100Yen = {1} ret = {2}", count10Yen, count100Yen, ret);
		
		return ret;
	}
};

class BWar2 {
	public static void Main() {
		// ??\???
		string[] inputStr_init = System.Console.ReadLine().Split(' ');
		int memberCount       = int.Parse(inputStr_init[0]);
		int init10YenCount    = int.Parse(inputStr_init[1]);
		int init100YenCount   = int.Parse(inputStr_init[2]);
		int init10YenCapacity = int.Parse(inputStr_init[3]);
		
		VendingMachine vm    = new VendingMachine(init10YenCount, init100YenCount, init10YenCapacity);// ??????????????????
		Member_2DR[] members = new Member_2DR[memberCount];
		for (int i = 0; i < memberCount; ++i) { // ?????????????????????
			string[] inputStr = System.Console.ReadLine().Split(' ');
			int own10YenCount  = int.Parse(inputStr[0]);
			int own100YenCount = int.Parse(inputStr[1]);
			members[i] = new Member_2DR(own10YenCount, own100YenCount);
		}
		
		int turn = 0; // ???????????????????????????
		while (members[turn].insertCoin(vm)) {
			//System.Console.WriteLine("turn = {0} end", turn);
			turn = (turn + 1) % memberCount; // ??????????????????????????????????????\????????????
		}
		System.Console.WriteLine("{0}", turn + 1);
	}
};

Measured memory_bytes: 9164