p,q = map(int,input().split()) N = int(input()) def gcd(a,b): if b == 0:return a while True: r =a % b a = b b = r if r == 0:return a ans = 0 d = gcd(p,q) flag = False if d != 0: p //= d q //= d if (p+q) % 2 == 0: flag = True for _ in range(N): x,y = map(int,input().split()) if d == 0: if x == 0 and y == 0:ans += 1 continue if x % d == 0 and y % d == 0: x //= d y //= d if flag: if (x+y)% 2 == 0:ans+= 1 else:ans += 1 print(ans)