a, b, c, d = map(int, input().split()) n = int(input()) xy = [list(map(int, input().split())) for _ in range(n)] # 横移動 if a == c == 0: while b > 0: d, b = b, d % b else: if a < c: a, b, c, d = c, d, a, b while c > 0: r = a // c a, b, c, d = c, d, a - r * c, b - r * d d = abs(d) nxy = [] for x, y in xy: nxy.append([x % a, y - b * (x // a)]) xy = nxy ki = set() # 縦移動 if d: for x, y in xy: ki.add((x, y % d)) else: for x, y in xy: ki.add((x, y)) print(len(ki))