#!/usr/bin/env python3.8 # %% import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines from math import gcd # %% a, b, c, d = map(int, readline().split()) N = int(readline()) m = map(int, read().split()) X, Y = zip(*zip(m, m)) # %% def fund_transform(a, b, c, d): while True: if a < c: a, c = c, a b, d = d, b if c == 0: if a == 0: b = abs(gcd(b, d)) d = 0 elif d == 0: pass else: d = abs(d) b %= d return a, b, c, d n = a // c a -= n * c b -= n * d def calc_key(x, y): if not a: y %= b return b * x + y n = x // a x -= a * n y -= b * n if not d: return a * y + x y %= d return a * y + x # %% a, b, c, d = fund_transform(a, b, c, d) keys = (calc_key(x, y) for x, y in zip(X, Y)) print(len(set(keys)))