#include using namespace std; using i64 = long long; int main() { cin.tie(nullptr)->sync_with_stdio(false); auto solve = [&]() { int n; cin >> n; vector> x(n); for (auto &[a, b] : x) { cin >> a >> b; } int q; cin >> q; vector> y(q); for (int i = 0; i < q; i++) { cin >> y[i][0] >> y[i][1]; y[i][2] = i; } sort(x.begin(), x.end()); sort(y.begin(), y.end()); map cnt; vector ans(q); for (int j = 0; auto [c, d, i] : y) { while (j < x.size() && x[j][0] <= c) { cnt[x[j][1]]++; j++; } ans[i] = j - cnt[d]; } for (int i = 0; i < q; i++) { cout << ans[i] << '\n'; } }; solve(); return 0; }