#include using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); ++i) #define all(a) a.begin(), a.end() #define arr(a) a.rbegin(), a.rend() using ll = long long; //Konishii int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector> cnt(int(1e5 + 1)); map m; rep(i, n) { int a, b; cin >> a >> b; cnt[b].push_back(a); m[a]++; } rep(i, int(1e5+1)) { if(cnt[i].size()) { sort(all(cnt[i])); } } m[0] = 0; ll pre = 0; for(auto [k, v] : m) { m[k] += m[pre]; pre = k; } m[int(1e5) + 1] = m[pre]; int q; cin >> q; rep(i, q) { int x, y; cin >> x >> y; auto it = m.lower_bound(x); int mi = upper_bound(all(cnt[y]), x) - cnt[y].begin(); if(it->first == x) { cout << m[x] - mi << "\n"; } else { it--; cout << m[it->first] - mi << "\n"; } } }