#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};
mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;
    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }
    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
}
#[allow(unused_macros)]
macro_rules ! get { ( $ t : ty ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . trim ( ) . parse ::<$ t > ( ) . unwrap ( ) } } ; ( $ ( $ t : ty ) ,* ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; let mut iter = line . split_whitespace ( ) ; ( $ ( iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) , ) * ) } } ; ( $ t : ty ; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ ( $ t : ty ) ,*; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ ( $ t ) ,* ) ) . collect ::< Vec < _ >> ( ) } ; ( $ t : ty ;; ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . split_whitespace ( ) . map ( | t | t . parse ::<$ t > ( ) . unwrap ( ) ) . collect ::< Vec < _ >> ( ) } } ; }
#[allow(unused_macros)]
macro_rules ! debug { ( $ ( $ a : expr ) ,* ) => { println ! ( concat ! ( $ ( stringify ! ( $ a ) , " = {:?}, " ) ,* ) , $ ( $ a ) ,* ) ; } }

fn make_tree(
    depth: usize,
    nodes: &mut Vec<(usize, Option<usize>, Option<usize>)>,
    seq: &mut Vec<(i64, i64, usize)>,
    l: usize,
    r: usize,
) -> Option<usize> {
    if !(l < r) {
        return None;
    }

    let mid = (l + r) / 2;

    if depth % 2 == 0 {
        seq[l..r].sort_by_key(|t| t.0);
    } else {
        seq[l..r].sort_by_key(|t| t.1);
    }

    let t = nodes.len();
    nodes.push((mid, None, None));
    nodes[t].1 = make_tree(depth + 1, nodes, seq, l, mid);
    nodes[t].2 = make_tree(depth + 1, nodes, seq, mid + 1, r);
    Some(t)
}

fn find(
    depth: usize,
    node: usize,
    seq: &[(i64, i64, usize)],
    tree: &[(usize, Option<usize>, Option<usize>)],
    sx: i64,
    sy: i64,
    tx: i64,
    ty: i64,
    v: &mut Vec<usize>,
) {
    let (t, l, r) = tree[node];
    let (x, y, i) = seq[t];

    if sx <= x && x <= tx && sy <= y && y <= ty {
        v.push(i);
    }

    if depth % 2 == 0 {
        if l.is_some() && sx <= x {
            find(depth + 1, l.unwrap(), seq, tree, sx, sy, tx, ty, v);
        }
        if r.is_some() && tx >= x {
            find(depth + 1, r.unwrap(), seq, tree, sx, sy, tx, ty, v);
        }
    } else {
        if l.is_some() && sy <= y {
            find(depth + 1, l.unwrap(), seq, tree, sx, sy, tx, ty, v);
        }
        if r.is_some() && ty >= y {
            find(depth + 1, r.unwrap(), seq, tree, sx, sy, tx, ty, v);
        }
    }
}

fn main() {
    let out = stdout();
    let mut out = BufWriter::new(out.lock());

    let n = get!(usize);
    let xy = get!(i64, i64; n);
    let mut seq: Vec<(i64, i64, usize)> = xy.into_iter()
        .enumerate()
        .map(|(i, (x, y))| (x, y, i))
        .collect();

    let mut tree = Vec::new();
    make_tree(0, &mut tree, &mut seq, 0, n);

    let q = get!(usize);
    for _ in 0..q {
        let (sx, tx, sy, ty) = get!(i64, i64, i64, i64);
        let mut v = Vec::new();
        find(0, 0, &seq, &tree, sx, sy, tx, ty, &mut v);
        v.sort();
        for &x in &v {
            writeln!(out, "{}", x).unwrap();
        }
        writeln!(out, "").unwrap();
    }
}



Measured memory_bytes: 39276