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