from math import gcd p, q = map(int, input().split()) 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)