#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

#define NIL (-1)

class Point{
public:
  int x, y, id;
};

class Node{
public:
  int l, r, location;
};

bool lessX(const Point &p1, const Point &p2){return p1.x < p2.x;};
bool lessY(const Point &p1, const Point &p2){return p1.y < p2.y;};

/* 0-indexed only */
class kDTree{
private:
  Point *P;
  Node *Tree;
  int n;
  int np;
  int root;
public:
  kDTree(int x[], int y[], int id[], int N);
  ~kDTree();
  int make_tree(int l, int r, int depth);
  void find_func(int sx, int tx, int sy, int ty, vector<Point> &ans);
  void find(int v, int sx, int tx, int sy, int ty, int depth, vector<Point> &ans);
};

kDTree::kDTree(int x[], int y[], int id[], int N){
  n = N;
  P = new Point[n];
  Tree = new Node[n];
  for(int i=0;i<n;i++){
    P[i].x = x[i];
    P[i].y = y[i];
    P[i].id = id[i];
  }
  np = 0;
  root = make_tree(0, n, 0);
}

kDTree::~kDTree(){
  delete [] P;
  delete [] Tree;
}

int kDTree::make_tree(int l, int r, int depth){
  if(!(l<r)) return NIL;
  int mid = (l+r)/2;
  int t = np++;

  if(depth%2 == 0){
    sort(P+l, P+r, lessX);
  }
  else{
    sort(P+l, P+r, lessY);
  }
  Tree[t].location = mid;
  Tree[t].l = make_tree(l, mid, depth+1);
  Tree[t].r = make_tree(mid+1, r, depth+1);

  return t;
}

void kDTree::find_func(int sx, int tx, int sy, int ty, vector<Point> &ans){
  find(root, sx, tx, sy, ty, 0, ans);
}

void kDTree::find(int v, int sx, int tx, int sy, int ty, int depth, vector<Point> &ans){
  int x = P[Tree[v].location].x;
  int y = P[Tree[v].location].y;

  if(sx<=x && x<=tx && sy<=y && y<=ty){
    ans.push_back(P[Tree[v].location]);
  }

  if(depth%2 == 0){
    if(Tree[v].l != NIL){
      if(sx<=x) find(Tree[v].l, sx, tx, sy, ty, depth+1, ans);
    }
    if(Tree[v].r != NIL){
      if(x<=tx) find(Tree[v].r, sx, tx, sy, ty, depth+1, ans);
    }
  }
  else{
    if(Tree[v].l != NIL){
      if(sy<=y) find(Tree[v].l, sx, tx, sy, ty, depth+1, ans);
    }
    if(Tree[v].r != NIL){
      if(y<=ty) find(Tree[v].r, sx, tx, sy, ty, depth+1, ans);
    }
  }
}

int main(void){
  int N;
  scanf("%d", &N);
  int x[N], y[N], id[N];
  for(int i=0;i<N;i++){
    scanf("%d %d", &x[i], &y[i]);
    id[i] = i;
  }

  kDTree kdtree(x, y, id, N);

  int q;
  scanf("%d", &q);
  int sx, tx, sy, ty;
  vector<Point> ans;
  priority_queue<int, vector<int>, greater<int> > ansid;

  for(int i=0;i<q;i++){
    scanf("%d %d %d %d", &sx, &tx, &sy, &ty);
    ans.clear();
    kdtree.find_func(sx, tx, sy, ty, ans);
    for(int j=0;j<ans.size();j++){
      ansid.push(ans[j].id);
    }
    for(int j=0;j<ans.size();j++){
      printf("%d\n", ansid.top());
      ansid.pop();
    }
    printf("\n");
  }

  return 0;
}

Measured memory_bytes: 18280