#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

// typedef pair<int,int> P;
// #define all(v) (v).begin(),(v).end()

template<typename T> class segtree
{
public:
    using ptt = pair<T,T>;
    vector<ptt> org,sorg;
    vector<vector<int> > id;
    vector<vector<T> > apl;
    //各座標が値(val)を持っているとき
    // vector<T> val;
    int n,sz;
    segtree(vector<ptt>& vec){
        sz = (int)vec.size();
        n = 1;
        while(n < sz){
            n *= 2;
        }
        org = vec, sorg = org;
        sort(all(sorg));
        id.resize(2*n-1), apl.resize(2*n-1);
        vector<int> index(sz);
        iota(all(index),0);
        sort(all(index),[&](int a, int b){
            return org[a] < org[b];
        });
        rep(i,sz){
            id[i+n-1].push_back(index[i]);
            apl[i+n-1].push_back(org[index[i]].second);
        }
        for(int i = n-2; i >= 0; i--){
            id[i].resize((int)id[2*i+1].size()+id[2*i+2].size());
            merge(all(id[2*i+1]),all(id[2*i+2]),id[i].begin(),[&](int a, int b){
                return org[a].second < org[b].second;
            });
            apl[i].resize((int)id[i].size());
            rep(j,(int)id[i].size()){
                apl[i][j] = org[id[i][j]].second;
            }
        }
    }
    vector<int> query(int a,int b,const T infy,const T supy,int k=0,int l=0,int r=-1)
    {
        if(r < 0) r = n;
        if(r <= a || b <= l){
            return vector<int>();
        }
        if(a <= l && r <= b){
            int lid = lower_bound(all(apl[k]),infy) - apl[k].begin();
            int rid = upper_bound(all(apl[k]),supy) - apl[k].begin();
            vector<int> ans(rid-lid);
            for(int i = lid; i < rid; i++){
                ans[i-lid] = id[k][i];
            }
            sort(all(ans));
            return ans;
        }else{
            vector<int> vl = query(a,b,infy,supy,2*k+1,l,(l+r)/2);
            vector<int> vr = query(a,b,infy,supy,2*k+2,(l+r)/2,r);
            vector<int> res((int)vl.size()+(int)vr.size());
            merge(all(vl),all(vr),res.begin());
            return res;
        }
    }
    //左下がl,右上がrの長方形領域に含まれる点の個数
    void query(const ptt l, const ptt r)
    {
        int lid = lower_bound(all(sorg),l) - sorg.begin();
        int rid = upper_bound(all(sorg),r) - sorg.begin();
        vector<int> ans = query(lid,rid,l.second,r.second);
        rep(i,len(ans)){
            cout << ans[i] << "\n";
        }
    }
};

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vp vec(n);
    rep(i,n){
        cin >> vec[i].fi >> vec[i].se;
    }
    segtree<int> sg(vec);
    int q;
    cin >> q;
    rep(i,q){
        P l,r;
        cin >> l.fi >> r.fi >> l.se >> r.se;
        sg.query(l,r);
        cout << "\n";
    }
    return 0;
}



Measured memory_bytes: 187292