#include using namespace std; using lint = long long; template using V = vector; template using VV = V< V >; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); lint a, b, c, d; cin >> a >> b >> c >> d; while (a) { lint q = c / a; swap(c -= q * a, a); swap(d -= q * b, b); } b = abs(b); int n; cin >> n; set< pair > se; while (n--) { lint x, y; cin >> x >> y; lint q = x / c; x -= q * c; y -= q * d; se.emplace(x, b ? (y % b + b) % b : y); } cout << se.size() << '\n'; }