#!/usr/bin/env python3 import math def gcd2(a, b, c, d): while a: k = c // a a, c = c - k * a, a b, d = d - k * b, b return a, b, c, d def solve(a, b, c, d, n, p): a, b, c, d = gcd2(a, b, c, d) assert a == 0 found = set() for x, y in p: if c: k = x // c x1 = x - k * c y1 = y - k * d if b: y1 %= b else: x1 = x y1 = y % math.gcd(b, d) found.add((x1, y1)) return len(found) def main(): a, b, c, d = map(int, input().split()) n = int(input()) p = [tuple(map(int, input().split())) for _ in range(n)] print(solve(a, b, c, d, n, p)) if __name__ == '__main__': main()