read = open('game.in').readline
n, m, k, r = map(int, read().split())
assert 1 <= n <= 100000 and 1 <= m <= 100000 and 1 <= k <= 100000
assert abs(r) <= m
low = high = r
ans1 = ans2 = -1
add_high = {'0 1': 1, '1 1': k, '1 0': -1, '0 0': 0}
add_low = {'0 1': 1, '1 1': -k, '1 0': -1, '0 0': 0}
for i in range(n):
	s = read().strip()
	assert len(s) == 3 and s[0] in ['0', '1'] and s[2] in ['0', '1'] and s[1] == ' '
	high += add_high[s]
	low += add_low[s]
	if high > m and ans1 == -1:
		ans1 = i + 1
	if low < -m and ans2 == -1:
		ans2 = i + 1
print >> open('game.out', 'w'), ans1, ans2
