N, M, P, Q = map(int, input().split()) querys = [list(map(int, input().split())) for _ in range(Q)] for x, f in querys: count = 0 answer = M // P tmp = M % P now = x while tmp >= count and f != 0: if (f-now) % x == 0: if ((f-now)//x + 1) + count <= tmp: answer += 1 break count += (P-now)//x + 1 now = (x - (P-now)%x) % x print(answer)