#include #include #define rep(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++) using namespace atcoder; using namespace std; typedef long long ll; template int smaller(vector &a, T x) { return lower_bound(a.begin(), a.end(), x) - a.begin(); } template int or_smaller(vector &a, T x) { return upper_bound(a.begin(), a.end(), x) - a.begin(); } template int bigger(vector &a, T x) { return a.size() - or_smaller(a, x); } template int or_bigger(vector &a, T x) { return a.size() - smaller(a, x); } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector> v(100010); vector w; rep(i, 0, n) { int a, b; cin >> a >> b; v[b].push_back(a); w.push_back(a); } rep(i, 0, 100010) { sort(v[i].begin(), v[i].end()); } sort(w.begin(), w.end()); int q; cin >> q; while (q--) { int x, y; cin >> x >> y; int ans = or_smaller(w, x); ans -= or_smaller(v[y], x); cout << ans << '\n'; } }