var
	n, k, i: longint;
	m, r, low, high: int64;
	ans1, ans2: longint;
	a, b: integer;
begin
	assign(input, 'game.in');
	assign(output, 'game.out');
	reset(input);
	rewrite(output);
	read(n, m, k, r);
	low := r;
	high := r;
	ans1 := -1;
	ans2 := -1;
	assert ((1 <= n) and (n <= 100000) and (1 <= m) and (m <= 100000) and (1 <= k) and (k <= 100000));
	assert (abs(r) <= m);
	for i := 1 to n do begin
		read(a, b);
		assert ((a = 0) or (a = 1));
		assert ((b = 0) or (b = 1));
		if (a = 0) and (b = 1) then	begin
			inc(low);
			inc(high);
		end;
		if (a = 1) and (b = 0) then begin
			dec(low);
			dec(high);
		end;
		if (a = 1) and (b = 1) then begin
			low := low - k;
			high := high + k;
		end;
		if (high > m) and (ans1 = -1) then
			ans1 := i;
		if (low < -m) and (ans2 = -1) then
			ans2 := i;
	end;
	writeln(ans1, ' ', ans2);
end.
