import sys
from math import gcd

input = sys.stdin.buffer.readline

A, B, C, D = map(int, input().split())
N = int(input())
XY = [tuple(map(int, input().split())) for _ in range(N)]

det = A * D - B * C

st = set()
if det:
    for X, Y in XY:
        st.add(((D * X - C * Y) % det,
                (-B * X + A * Y) % det))
else:
    gAC = gcd(A, C)
    gBD = gcd(B, D)

    if not gAC:
        for X, Y in XY:
            st.add((X, 0))
    elif not gBD:
        for X, Y in XY:
            st.add((0, Y))
    else:
        for X, Y in XY:
            M = min(X // gAC, Y // gBD)
            st.add((X - M * gAC, Y - M * gBD))
print(len(st))