#include using namespace std; typedef long long LL; const int maxn = 200005; struct P { LL x, y; }; P a[maxn]; bool cmp(P p, P q) { if (p.x != q.x) return p.x < q.x; return p.y < q.y; } LL LLabs(LL x) { return x < 0 ? -x : x; } LL gcd_func(LL x, LL y) { x = LLabs(x); y = LLabs(y); while (y) { LL r = x % y; x = y; y = r; } return x; } int main() { LL a1, b1, c1, d1; cin >> a1 >> b1 >> c1 >> d1; int n; cin >> n; LL h11 = a1, h21 = b1, h12 = c1, h22 = d1; while (h12 != 0) { LL q = h11 / h12; LL r1 = h11 - q * h12; LL r2 = h21 - q * h22; h11 = h12; h21 = h22; h12 = r1; h22 = r2; } if (h11 < 0) { h11 = -h11; h21 = -h21; } if (h11 == 0) { LL g = gcd_func(h21, h22); h21 = 0; h22 = g; } else { if (h22 < 0) h22 = -h22; if (h22 > 0) { h21 = (h21 % h22 + h22) % h22; } } for (int i = 1; i <= n; i++) { LL x, y; cin >> x >> y; if (h11 == 0) { a[i].x = x; if (h22 > 0) { a[i].y = (y % h22 + h22) % h22; } else { a[i].y = y; } } else { LL rx = (x % h11 + h11) % h11; LL k = (x - rx) / h11; __int128 tmp = y - (__int128)k * h21; a[i].x = rx; if (h22 > 0) { a[i].y = (LL)((tmp % h22 + h22) % h22); } else { a[i].y = (LL)tmp; } } } sort(a + 1, a + n + 1, cmp); int ans = 0; for (int i = 1; i <= n; i++) { if (i == 1 || a[i].x != a[i - 1].x || a[i].y != a[i - 1].y) { ans++; } } cout << ans << endl; return 0; }