p, q = gets.split.map(&:to_i).map(&:abs)

gcd = p.gcd(q)
p /= gcd
q /= gcd
type = [p,q]==[0,0] ? 0 : [p,q]==[1,1] ? 1 : p.odd?&&q.odd? ? 2 : 3

count = 0
gets.to_i.times{
	x, y = gets.split.map(&:to_i).map(&:abs)
	
	break if x % gcd != 0 || y % gcd != 0
	x %= gcd; y %= gcd

	case type
	when 0
		count += 1
	when 1
		count += 1 if (x+y).even?
	when 2
		count += 1 if (x+y).even?
	when 3
		count += 1
	end
}
puts count