/** * @brief テンプレート */ // #pragma GCC target("avx2") // #pragma GCC optimize("O3") // #pragma GCC optimize("unroll-loops") #include using namespace std; using ll = long long; using ull = unsigned long long; using vl = vector; using vvl = vector; using vvvl = vector; using pl = pair; using vp = vector; using vvp = vector; using vs = vector; using vvs = vector; using vb = vector; using vvb = vector; using vvvb = vector; using vd = vector; using vvd = vector; using vvvd = vector; #define _overload3(_1, _2, _3, name, ...) name #define _rep(i, n) repi(i, 0, n) #define repi(i, a, b) for(ll i = ll(a); i < ll(b); ++i) #define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__) #define all(x) std::begin(x), std::end(x) constexpr ll inf = 0x1fffffffffffffffLL; // 2.3 * 10^18 template istream &operator>>(istream &is, pair &p) { is >> p.first >> p.second; return is; } template ostream &operator<<(ostream &os, pair &p) { os << p.first << " " << p.second; return os; } template istream &operator>>(istream &is, vector &v) { for(auto &x : v) { is >> x; } return is; } template ostream &operator<<(ostream &os, const vector &v) { for(int i = 0; i < (int)v.size(); i++) { if(i != (int)v.size() - 1) os << v[i] << " "; else os << v[i]; } return os; } template auto vec(T x, int arg, Args... args) { if constexpr(sizeof...(args) == 0) return vector(arg, x); else return vector(arg, vec(x, args...)); } template bool chmin(T &a, const T &b) { return a > b ? a = b, true : false; } template bool chmax(T &a, const T &b) { return a < b ? a = b, true : false; } constexpr ll bit(ll x) { return 1LL << x; } constexpr ll msk(ll x) { return (1LL << x) - 1; } constexpr bool stand(ll x, int i) { return x & bit(i); } /** * @brief Debug */ #ifdef LOCAL #define debug_assert(exp) assert(exp) #else #define debug_assert(exp) true #endif #ifdef LOCAL #define dbg(x) std::cerr << __LINE__ << " : " << #x << " = " << (x) << std::endl #else #define dbg(x) true #endif // #include // using namespace atcoder; // generated by oj-template v4.8.1 (https://github.com/online-judge-tools/template-generator) int main() { ll N; cin >> N; vl A(N), B(N); rep(i, N) cin >> A[i] >> B[i]; vvl v(100100); rep(i, N) { v[B[i]].emplace_back(A[i]); } rep(i, 100100) sort(all(v[i])); sort(all(A)); ll Q; cin >> Q; while(Q--) { ll X, Y; cin >> X >> Y; cout << distance(A.begin(), lower_bound(all(A), X + 1)) - distance(v[Y].begin(), lower_bound(all(v[Y]), X + 1)) << endl; } }