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) 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: ans += 1 print(ans)