def gcd(a, b): # 最大公約数 while b > 0: a, b = b, a % b return a def is_reachable(p, q, x, y): if p == 0: if q == 0: return x == 0 and y == 0 else: return x % q == 0 and y % q == 0 gap = gcd(p, q) if p % 2 == q % 2: if gap == 1: return x % 2 == 0 and y % 2 == 0 elif gap == p: gap = 2*p return (x%gap == 0 and y%gap==0) or ((x+p)%gap ==0 and (y+p)%gap==0) else: return (x % p == 0 and (y + gap) % p==0) or ((x + gap) % p == 0 and y % p==0) else: if gap == 1: return True elif gap == p: return x % p == 0 and y % p == 0 else: return (x % p == 0 and (y + gap) % p==0) or ((x + gap) % p == 0 and y % p==0) P, Q = map(int, input().split()) if P > Q: P, Q = Q, P N = int(input()) cnt = 0 for i in range(N): x, y = map(int, input().split()) if is_reachable(P, Q, x, y): # print(x, y, 'is good child') cnt += 1 print(cnt)