class UnionFind: def __init__(self, n): self.node = [-1 for _ in range(n)] def root(self, v): if self.node[v] < 0: return v st = [] while self.node[v] >= 0: st.append(v) v = self.node[v] for u in st: self.node[u] = v return v def size(self, v): v = self.root(v) return (- self.node[v]) def same(self, u, v): return self.root(u) == self.root(v) def unite(self, u, v): ru = self.root(u) rv = self.root(v) if ru == rv: return du = self.node[ru] dv = self.node[rv] if du <= dv: self.node[rv] = ru self.node[ru] += dv else: self.node[ru] = rv self.node[rv] += du a, b, c, d = map(int, input().split()) n = int(input()) points = [list(map(int, input().split())) for _ in range(n)] uf = UnionFind(n) idx = {} pairs = [(a, b), (c, d)] for i in range(2): xb, yb = pairs[i] for v in range(n): x, y = points[v] if xb != 0: x %= xb if yb != 0: y %= yb if idx.get((x, y), None) is None: idx[x, y] = v else: uf.unite(idx[x, y], v) roots = {} for v in range(n): r = uf.root(v) roots[r] = roots.get(r, 0) + 1 print(len(roots))