#!/usr/bin/env python3
import math
p, q = map(int,input().split())
n = int(input())
gcd = math.gcd(p, q)
even = (p / gcd) % 2 == 0 or (q / gcd) % 2 == 0
ans = 0
for i in range(n):
    x, y = map(int,input().split())
    if x % gcd == 0 and y % gcd == 0:
        if even:
            ans += 1
        else:
            if ((x / gcd) + (y / gcd)) % 2 == 0:
                ans += 1
print(ans)