#include using namespace std; int main(){ ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector> tb(100001); vector a(n); for(int i = 0; i < n; i++){ int x, y; cin >> x >> y; a[i] = x; tb[y].emplace_back(x); } sort(a.begin(), a.end()); for(auto &&vec : tb) sort(vec.begin(), vec.end()); int Q; cin >> Q; while(Q--){ int x, y; cin >> x >> y; int ans = upper_bound(a.begin(), a.end(), x) - a.begin(); ans -= upper_bound(tb[y].begin(), tb[y].end(), x) - tb[y].begin(); cout << ans << '\n'; } }