a, b, c, d = map(int, input().split()) n = int(input()) XY = [] for i in range(n): x, y = map(int, input().split()) XY.append((x, y)) import math det = a*d-b*c S = set() if det == 0: g1 = math.gcd(a, c) g2 = math.gcd(b, d) for x, y in XY: if g1 != 0 and g2 != 0: q = min(x//g1, y//g2) x = x-q*g1 y = y-q*g2 S.add((x, y)) elif g1 == 0: q = y//g2 y = y-q*g2 S.add((x, y)) elif g2 == 0: q = x//g1 x = x-q*g1 S.add((x, y)) else: det = abs(det) S = set() for x, y in XY: z = (d*x-c*y)%det w = (-b*x+a*y)%det S.add((z, w)) print(len(S))