lib C fun strtoll(s : UInt8*, p : UInt8**, b : Int32) : Int64 end class String def to_i64 C.strtoll(self, nil, 10) end end p, q = read_line.split.map(&.to_i64) n = read_line.to_i g = p.gcd(q) if g > 0 p //= g q //= g end puts (0...n).count { x, y = read_line.split.map(&.to_i64) if g == 0 {x, y} == {0, 0} elsif (p + q).even? {x % g, y % g} == {0, 0} && (x // g + y // g).even? else {x % g, y % g} == {0, 0} end }