#include<iostream>
using namespace std;
#include<cstdio>
#include<algorithm>

struct point{ int x, y, id; };

point init(int pos_x, int pos_y, int index)
{
    point p; 
    p.x = pos_x, p.y = pos_y, p.id = index; 
    return p;
}

bool cmp_x(const point &P1, const point &P2){ if(P1.x != P2.x){ return P1.x < P2.x; } return P1.y < P2.y; }
bool cmp_y(const point &P1, const point &P2){ if(P1.y != P2.y){ return P1.y < P2.y; } return P1.x < P2.x; }

typedef struct node{ point mark; node *less, *more; } kd_node;

kd_node* init(point pos, node* l, node* m)
{
    kd_node* node = new kd_node;
    node->mark = pos, node->less = l, node->more = m;
    return node;
}

kd_node* kd_tree(point *S, point *T, point *U, int left, int right, int d)
{
    if(left == right) return NULL;
    if(left + 1 == right){
        kd_node* leaf = new kd_node;
        leaf->less = NULL, leaf->more = NULL;
        if((d & 1) == 0){
            leaf->mark = S[left];
        }else{
            leaf->mark = T[left];
        }
        return leaf;
    }

    kd_node* node = new kd_node;
    int mid = (left + right) / 2;
    int a = left, b = mid;

    if((d & 1) == 0){
        node->mark = S[mid];
        for(int i = left; i < right; i++){  // sort.
            if(cmp_x(T[i], S[mid])){
                U[a] = T[i], a++;
            }else{
                U[b] = T[i], b++;
            }
        }
        for(int i = left; i < right; i++){ T[i] = U[i]; }

    }else{
        node->mark = T[mid];
        for(int i = left; i < right; i++){  // sort.
            if(cmp_y(S[i], T[mid])){
                U[a] = S[i], a++;
            }else{
                U[b] = S[i], b++;
            }
        }
        for(int i = left; i < right; i++){ S[i] = U[i]; }
    }
    node->less = kd_tree(S, T, U, left, mid, d + 1);
    node->more = kd_tree(S, T, U, mid, right, d + 1);

    return node;
}

int cnt;

void find_pt(int *Q, int sx, int tx, int sy, int ty, kd_node* node, int d)
{
    point p = node->mark;
    int a = p.x, b = p.y;

    if(node->less == NULL && node->more == NULL){
        if(sx <= a && a <= tx && sy <= b && b <= ty){
            Q[cnt] = p.id, cnt++;
        }
        return;
    }
    if((d & 1) == 0){
        if(sx <= a){ find_pt(Q, sx, tx, sy, ty, node->less, d + 1); }
        if(a <= tx){ find_pt(Q, sx, tx, sy, ty, node->more, d + 1); }
    }else{
        if(sy <= b){ find_pt(Q, sx, tx, sy, ty, node->less, d + 1); }
        if(b <= ty){ find_pt(Q, sx, tx, sy, ty, node->more, d + 1); }
    }
    return;
}

int main()
{
    point *S, *T, *U;
    int Q[100];
    int i, pos_x, pos_y, n;
    scanf("%d", &n);

    S = new point [n], T = new point [n], U = new point [n];

    for(i = 0; i < n; i++){
        scanf("%d %d", &pos_x, &pos_y);
        S[i] = init(pos_x, pos_y, i);
        T[i] = S[i];
    }
    sort(S, S + n, cmp_x);
    sort(T, T + n, cmp_y);

    kd_node* root = kd_tree(S, T, U, 0, n, 0);

    int sx, tx, sy, ty, q;
    scanf("%d", &q);
    while(q){
        cnt = 0;
        scanf("%d %d %d %d", &sx, &tx, &sy, &ty);
        find_pt(Q, sx, tx, sy, ty, root, 0);
        sort(Q, Q + cnt);
        for(int i = 0; i < cnt; i++){ printf("%d\n", Q[i]); }
        printf("\n");
        q--;
    }
    delete [] S, delete [] T, delete [] U;

    return 0;
}

Measured memory_bytes: 63952