import sys input = sys.stdin.readline from math import gcd P, Q = map(int, input().split()) g = gcd(P, Q) P //= g Q //= g ans = 0 N = int(input()) for _ in range(N): X, Y = map(int, input().split()) if X % g or Y % g: continue X //= g Y //= g if P % 2 == 0 or Q % 2 == 0: ans += 1 continue if X % 2 == Y % 2: ans += 1 print(ans)