using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class KDTree
    {
        readonly int n;

        Node[] nodes;
        Point[] points;
        int root;

        public KDTree(int n)
        {
            this.n = n;

            nodes = new Node[n];
            points = new Point[n];
        }

        public void AddPoint(int id, int x, int y)
        {
            points[id].id = id;
            points[id].x = x;
            points[id].y = y;
        }

        public void MakeKDTree()
        {
            root = MakeKDTree(0, n, 0);
        }

        private int MakeKDTree(int l, int r, int depth)
        {
            if (l >= r) return -1;

            int mid = (l + r) / 2;

            if (depth % 2 == 0) Array.Sort(points, l, r - l, new ComparerX());
            else Array.Sort(points, l, r - l, new ComparerY());

            nodes[mid].l = MakeKDTree(l, mid, depth + 1);
            nodes[mid].r = MakeKDTree(mid + 1, r, depth + 1);

            return mid;
        }

        public List<int> FindPoints(int sx, int tx, int sy, int ty)
        {
            List<int> idList = new List<int>();

            Find(root, sx, tx, sy, ty, 0, idList);

            return idList;
        }

        private void Find(int v, int sx, int tx, int sy, int ty, int depth, List<int> idList)
        {
            Node cur = nodes[v];
            Point p = points[v];
            int x = p.x;
            int y = p.y;

            if (sx <= x && x <= tx && sy <= y && y <= ty) idList.Add(p.id);

            if (depth % 2 == 0)
            {
                if (cur.l != -1 && sx <= x) Find(cur.l, sx, tx, sy, ty, depth + 1, idList);
                if (cur.r != -1 && x <= tx) Find(cur.r, sx, tx, sy, ty, depth + 1, idList);
            }
            else
            {
                if (cur.l != -1 && sy <= y) Find(cur.l, sx, tx, sy, ty, depth + 1, idList);
                if (cur.r != -1 && y <= ty) Find(cur.r, sx, tx, sy, ty, depth + 1, idList);
            }
        }
    }

    struct Node
    {
        internal int l, r;
    }

    struct Point
    {
        internal int id, x, y;
    }

    class ComparerX : IComparer<Point>
    {
        public int Compare(Point a, Point b)
        {
            return a.x - b.x;
        }
    }

    class ComparerY : IComparer<Point>
    {
        public int Compare(Point a, Point b)
        {
            return a.y - b.y;
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            KDTree T = new KDTree(n);

            for (int i = 0; i < n; i++)
            {
                int[] temp = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);

                T.AddPoint(i, temp[0], temp[1]);
            }

            T.MakeKDTree();

            int q = int.Parse(Console.ReadLine());

            StringBuilder sb = new StringBuilder();

            for (int i = q; i > 0; i--)
            {
                int[] temp = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);

                List<int> ans = T.FindPoints(temp[0], temp[1], temp[2], temp[3]);
                ans.Sort();

                foreach (var id in ans)
                {
                    sb.AppendLine(id.ToString());
                }
                sb.AppendLine();
            }
            Console.Write(sb);
        }
    }
}

Measured memory_bytes: 68304