n, m, s = [int(i) for i in input().split(" ")]
arr_n, arr_m = [], []
result = 0
for _ in range(max(n, m)):
a, b = input().split(" ")
if a != '-':
arr_n.append(int(a))
if b != '-':
arr_m.append(int(b))
suma = min(arr_n[0], arr_m[0])
while suma <= s:
print(arr_n, arr_m)
if arr_n[0] < arr_m[0]:
suma += arr_n[0]
arr_n.pop(0)
else:
suma += arr_m[0]
arr_m.pop(0)
result += 1
print(result)