#include <cstdio>
#include <algorithm>
#include <vector>
#define NMAX 500005
#define NUL -1
using namespace std;
int n, nowLocation = 0;
vector<int> result;
struct Node {
    int IOid, location, x, y, left, right;// id、二叉树位置、坐标、子节点
}nodes[NMAX];
/* 测试使用， 输出全部节点信息
void test(){
    printf("======================\n");
    for(int i=0;i<n;i++){
        printf("IOid:%d  id:%d  loc:%d  (%d, %d)  left:%d  right:%d\n", nodes[i].IOid, i, nodes[i].location, nodes[i].x, nodes[i].y, nodes[i].left, nodes[i].right);
    }
    printf("======================\n");
}*/

bool lessByX(const Node &node1, const Node &node2){return node1.x < node2.x;}
bool lessByY(const Node &node1, const Node &node2){return node1.y < node2.y;}

/**构建二叉树*/
int buildTree(int left, int right, int depth){
    if (left>=right)
        return NUL;//递归至叶节点
    int mid = (right+left)>>1;//中值
    int loc = nowLocation++;//用于计算id序列的变量
    if (depth++ % 2)//奇数行，以y坐标为基准升序排列
        sort(nodes+left, nodes+right, lessByY);
    else sort(nodes+left, nodes+right, lessByX);//偶数行
    /*测试时用，输出每次排序后的IOid顺序
    for(int i =0;i<n;i++){
        printf("%d ", nodes[i].IOid);
    }
    printf("\n");*/
    //printf("===loc:%d left:%d right:%d mid:%d\n", loc, left, right, mid);
    nodes[mid].location = loc;// 在二叉树中的位置
    nodes[mid].left = buildTree(left, mid, depth);//递归左子树
    //printf("nodes[%d]左子树返回: %d\n", mid, nodes[mid].left);
    nodes[mid].right = buildTree(mid+1, right, depth);//递归右子树
    //printf("nodes[%d]右子树返回: %d\n", mid, nodes[mid].right);
    return mid;
}

/**范围查询*/
void findNodes (int nowLoc, int xMin, int xMax, int yMin, int yMax, int depth) {
    int nowX = nodes[nowLoc].x;
    int nowY = nodes[nowLoc].y;

    //printf("now finding nodes which x:%d -> %d  y:%d -> %d with nowLoc=%d and x=%d, y=%d\n", xMin, xMax, yMin, yMax, nowLoc, nowX, nowY);

    //bool flag = false;
    if(nowX >= xMin && nowX <= xMax && nowY <= yMax && nowY >= yMin){
        result.push_back(nodes[nowLoc].IOid);//将查询到的节点保存到结果集
        // printf("found: nowLoc:%d  IOid:%d\n", nowLoc, nodes[nowLoc].IOid);
    }
    if(depth++ % 2) {//奇数行，比较y
        if(nodes[nowLoc].left!=NUL && nowY >= yMin)// y比最小值大，搜索左子树
            findNodes(nodes[nowLoc].left, xMin, xMax, yMin, yMax, depth);
        if(nodes[nowLoc].right!=NUL && nowY <= yMax)// y比最大值小，搜索右子树
            findNodes(nodes[nowLoc].right, xMin, xMax, yMin, yMax, depth);
    } else {//偶数行，比较x
        if(nodes[nowLoc].left!=NUL && nowX >= xMin)// x比最小值大，搜索左子树
            findNodes(nodes[nowLoc].left, xMin, xMax, yMin, yMax, depth);
        if(nodes[nowLoc].right!=NUL && nowX <= xMax)// x比最小值大，搜索右子树
            findNodes(nodes[nowLoc].right, xMin, xMax, yMin, yMax, depth);
    }
}

int main(){
    int xMin, xMax, yMin, yMax;
    short q;
    scanf("%d", &n);
    for (int i = 0;i<n;i++){
        scanf("%d%d", &nodes[i].x, &nodes[i].y);
        nodes[i].IOid = i;
    }
    int root = buildTree(0, n, 0);//构建二叉树
    //test();
    scanf("%d", &q);
    while (q--) {
        scanf("%d%d%d%d", &xMin, &xMax, &yMin, &yMax);
        findNodes(root, xMin, xMax, yMin, yMax, 0);//从二叉树的根节点执行查询
        sort(result.begin(), result.end());//对结果集进行排序
        int length = result.size();
        for(int i=0;i<length;i++){
            printf("%d\n", result[i]);
        }
        result.clear();//清空结果集
        printf("\n");
        //test();
    }
    return 0;
}



Measured memory_bytes: 14048