from math import gcd p, q = map(int, input().split()) if p == 0 and q == 0: ans = 0 n = int(input()) for _ in range(n): x, y = map(int, input().split()) if x == y == 0: ans += 1 print(ans) exit() g = gcd(p, q) p //= g q //= g if (p + q) % 2 == 0: bi = True else: bi = False n = int(input()) ans = 0 for _ in range(n): x, y = map(int, input().split()) if x % g != 0 or y % g != 0: continue x //= g y //= g if not bi or (x + y) % 2 == 0: ans += 1 print(ans)