import sys from collections import defaultdict def main(): a, b, c, d = map(int, sys.stdin.readline().split()) D = a * d - b * c N = int(sys.stdin.readline()) points = [tuple(map(int, sys.stdin.readline().split())) for _ in range(N)] if D == 0: groups = defaultdict(int) if a == 0: # v1 is (0, b), b != 0 for x, y in points: mod_y = y % b if b != 0 else y key = (x, mod_y) groups[key] += 1 elif b == 0: # v1 is (a, 0), a != 0 for x, y in points: mod_x = x % a if a != 0 else x key = (mod_x, y) groups[key] += 1 else: # a and b are non-zero denom = a * a + b * b for x, y in points: numerator = x * a + y * b k = numerator // denom rx = x - k * a ry = y - k * b key = (rx, ry) groups[key] += 1 else: groups = defaultdict(int) abs_D = abs(D) for x, y in points: mol_k = d * x - c * y mol_l = -b * x + a * y r_k = (mol_k % abs_D + abs_D) % abs_D r_l = (mol_l % abs_D + abs_D) % abs_D key = (r_k, r_l) groups[key] += 1 print(len(groups)) if __name__ == "__main__": main()