import math P,Q = list(map(int, input().split())) N = int(input()) g = math.gcd(P,Q) if g != 0: P = P // g Q = Q // g count = 0 for _ in range(N): x,y = list(map(int, input().split())) if g == 0: if x == 0 and y == 0: count = count + 1 continue if x % g != 0 or y % g != 0: continue x = x // g y = y // g if (P+Q) % 2 == 0 and (x+y) % 2 != 0: continue count = count + 1 print(count)