""" https://yukicoder.me/problems/no/321 場合分けかなぁ 1,3 X.X. ...X X... .X.X とりあえず必要条件を入れてみる """ import math P,Q = map(int,input().split()) P = abs(P) Q = abs(Q) GPQ = math.gcd(P,Q) GS = math.gcd(abs(P-Q),abs(P+Q)) N = int(input()) ans = 0 for i in range(N): X,Y = map(int,input().split()) X = abs(X) Y = abs(Y) flag = False if P == 0 and Q == 0: if X == Y == 0: flag = True else: if X % GPQ == 0 and Y % GPQ == 0 and (X+Y) % GS == 0 and abs(X-Y) % GS == 0: flag = True if flag: ans += 1 print (ans)