package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)

	n := getNextInt(scanner)
	xx := make(Ranks, n+40000, n+40000)
	yy := make([]int, n+40000, n+40000)
	rx := map[int]int{}
	ry := map[int]int{}
	pp := make(Points, n)

	for i := 0; i < n; i++ {
		pp[i].x = getNextInt(scanner)
		pp[i].y = getNextInt(scanner)
		pp[i].i = i
		xx[i].v = pp[i].x
		xx[i].q = 1
		yy[i] = pp[i].y
	}
	q := getNextInt(scanner)
	qq := make([]Query, q)
	xyi := n
	for i := 0; i < q; i++ {
		qq[i].sx = getNextInt(scanner)
		qq[i].tx = getNextInt(scanner) + 1
		xx[xyi].v = qq[i].sx
		xx[xyi].q = 0
		xx[xyi+1].v = qq[i].tx
		xx[xyi+1].q = 0
		qq[i].sy = getNextInt(scanner)
		qq[i].ty = getNextInt(scanner)
		yy[xyi] = qq[i].sy
		yy[xyi+1] = qq[i].ty
		xyi += 2
	}
	rcnt := q*2 + n
	sort.Sort(xx[0:rcnt])
	sort.Ints(yy[0:rcnt])
	rankx := 0
	ranky := 0
	if xx[0].q == 1 {
		rankx++
	} else {
		rx[xx[0].v] = rankx
	}

	for i := 1; i < rcnt; i++ {
		if yy[i] != yy[i-1] {
			ranky++
		}
		if xx[i].q == 1 {
			rankx++
		} else {
			rx[xx[i].v] = rankx
		}
		ry[yy[i]] = ranky
	}

	sort.Sort(pp)
	raw := make([]int, n, n)
	prev := make([]int, rcnt, rcnt)
	for i := 0; i < n; i++ {
		raw[i] = ry[pp[i].y]
		pp[i].prev = prev[raw[i]]
		prev[raw[i]] = i
	}
	wl := WaveletKeanuReeves{}
	wl.init(raw)

	ans := make([]int, 100, 100)

	for i := 0; i < q; i++ {
		sx := rx[qq[i].sx]
		tx := rx[qq[i].tx]

		ai := 0

		more := wl.rangerankmore(sx, tx, ry[qq[i].ty])
		for {
			c := wl.quantile(sx, tx, more+1)
			if c < ry[qq[i].sy] {
				break
			}
			l, r := wl.getbottomrange(sx, tx, c)
			cnt := r - l
			ti := wl.gettopindex(r - 1)
			for iii := 0; iii < cnt; iii++ {
				ans[ai] = pp[ti].i
				ti = pp[ti].prev
				ai++
			}
			more += cnt
		}

		sort.Ints(ans[0:ai])
		for ii := 0; ii < ai; ii++ {
			fmt.Fprintln(writer, ans[ii])
		}
		fmt.Fprintln(writer, "")
	}
	writer.Flush()
}

// Rank ...
type Rank struct {
	v, q int
}

// Ranks ...
type Ranks []Rank

func (a Ranks) Len() int      { return len(a) }
func (a Ranks) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a Ranks) Less(i, j int) bool {
	if a[i].v == a[j].v {
		return a[i].q < a[j].q
	}
	return a[i].v < a[j].v
}

// Point ...
type Point struct {
	x, y, i, prev int
}

// Points ...
type Points []Point

func (a Points) Len() int           { return len(a) }
func (a Points) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a Points) Less(i, j int) bool { return a[i].x < a[j].x }

// Query ...
type Query struct {
	sx, tx, sy, ty int
}

// WaveletKeanuReeves ...
type WaveletKeanuReeves struct {
	bits, n        int
	tree           [][]int
	data, topIndex []int
}

func (wl *WaveletKeanuReeves) init(raw []int) {
	n := len(raw)
	wl.bits = 20
	wl.tree = make([][]int, wl.bits, wl.bits)
	wl.data = make([]int, wl.bits*(n+1), wl.bits*(n+1))

	buf := make([]int, n, n)
	sorted := make([]int, n, n)
	wl.topIndex = make([]int, n, n)
	for i := 0; i < n; i++ {
		sorted[i] = i
		wl.topIndex[i] = -1
	}

	for i := wl.bits - 1; i >= 0; i-- {
		wl.tree[i] = wl.data[i*(n+1) : (i+1)*(n+1)]
		bi := 0
		si := 0
		for ii := 0; ii < n; ii++ {
			wl.tree[i][ii+1] = (raw[sorted[ii]] >> uint(i)) & 1
			if wl.tree[i][ii+1] == 0 {
				sorted[si] = sorted[ii]
				si++
			} else {
				buf[bi] = sorted[ii]
				bi++
			}
			wl.tree[i][ii+1] += wl.tree[i][ii]
		}
		for ii := 0; ii < bi; ii++ {
			sorted[si+ii] = buf[ii]
		}
	}

	wl.n = n
}

func (wl *WaveletKeanuReeves) count0(h, i int) int {
	return i - wl.tree[h][i]
}

func (wl *WaveletKeanuReeves) count1(h, i int) int {
	return wl.tree[h][i]
}

func (wl *WaveletKeanuReeves) next(h, i int) int {
	bit := wl.tree[h][i+1] - wl.tree[h][i]
	if bit == 0 {
		return wl.count0(h, i)
	}
	index := wl.count0(h, wl.n) + wl.tree[h][i]
	return index
}

func (wl *WaveletKeanuReeves) nextrange0(h, l, r int) (int, int) {
	return wl.count0(h, l), wl.count0(h, r)
}

func (wl *WaveletKeanuReeves) nextrange1(h, l, r int) (int, int) {
	start1 := wl.count0(h, wl.n)
	return start1 + wl.count1(h, l), start1 + wl.count1(h, r)
}

func (wl *WaveletKeanuReeves) access(at int) int {
	var ans int

	for i := wl.bits - 1; i >= 0; i-- {
		bit := wl.tree[i][at+1] - wl.tree[i][at]
		ans |= bit << uint(i)
		at = wl.next(i, at)
	}

	return ans
}

func (wl *WaveletKeanuReeves) rank(at, c int) int {
	l := 0
	r := at
	for i := wl.bits - 1; i >= 0 && l < r; i-- {
		bit := (c >> uint(i)) & 1
		if bit == 0 {
			l, r = wl.nextrange0(i, l, r)
			continue
		}
		l, r = wl.nextrange1(i, l, r)
	}

	return r - l
}

func (wl *WaveletKeanuReeves) rank0(h, at int) int {
	l := 0
	r := wl.n
	for l < r {
		m := (l + r) >> 1
		if wl.count0(h, m) < at+1 {
			l = m + 1
			continue
		}
		r = m
	}
	return l - 1
}

func (wl *WaveletKeanuReeves) rank1(h, at int) int {
	l := 0
	r := wl.n
	for l < r {
		m := (l + r) >> 1
		if wl.count1(h, m) < at+1 {
			l = m + 1
			continue
		}
		r = m
	}
	return l - 1
}

func (wl *WaveletKeanuReeves) selects(at, c int) int {
	l := 0
	r := wl.n
	for i := wl.bits - 1; i >= 0 && l < r; i-- {
		bit := (c >> uint(i)) & 1
		if bit == 0 {
			l, r = wl.nextrange0(i, l, r)
			continue
		}
		l, r = wl.nextrange1(i, l, r)
	}
	return wl.gettopindex(l + at)
}

func (wl *WaveletKeanuReeves) gettopindex(index int) int {
	if wl.topIndex[index] != -1 {
		return wl.topIndex[index]
	}
	ti := index
	for i := 0; i < wl.bits; i++ {
		index1 := wl.count0(i, wl.n)
		if index < index1 {
			index = wl.rank0(i, index)
			continue
		}
		index = wl.rank1(i, index-index1)
	}
	wl.topIndex[ti] = index
	return wl.topIndex[ti]
}

func (wl *WaveletKeanuReeves) getbottomrange(l, r, c int) (int, int) {
	for i := wl.bits - 1; i >= 0; i-- {
		bit := (c >> uint(i)) & 1
		if bit == 0 {
			l, r = wl.nextrange0(i, l, r)
			continue
		}
		l, r = wl.nextrange1(i, l, r)
	}
	return l, r
}

func (wl *WaveletKeanuReeves) quantile(l, r, rank int) int {
	if rank > r-l {
		return -1
	}
	var ans int
	for i := wl.bits - 1; i >= 0; i-- {
		c1 := wl.count1(i, r) - wl.count1(i, l)
		if c1 >= rank {
			ans |= 1 << uint(i)
			l, r = wl.nextrange1(i, l, r)
			continue
		}
		l, r = wl.nextrange0(i, l, r)
		rank -= c1
	}

	return ans
}

func (wl *WaveletKeanuReeves) rangerankless(l, r, c int) int {
	ans := 0
	for i := wl.bits - 1; i >= 0; i-- {
		bit := (c >> uint(i)) & 1
		if bit == 0 {
			l, r = wl.nextrange0(i, l, r)
			continue
		}
		ans += wl.count0(i, r) - wl.count0(i, l)
		l, r = wl.nextrange1(i, l, r)
	}

	return ans
}

func (wl *WaveletKeanuReeves) rangerankmore(l, r, c int) int {
	ans := 0
	var b uint
	b = uint(wl.bits)
	for i := wl.bits - 1; i >= 0; i-- {
		b--
		bit := (c >> b) & 1
		if bit == 1 {
			l, r = wl.nextrange1(i, l, r)
			continue
		}
		ans += wl.count1(i, r) - wl.count1(i, l)
		l, r = wl.nextrange0(i, l, r)
	}

	return ans
}

func (wl *WaveletKeanuReeves) rangefreq(l, r, min, max int) int {
	return wl.rangerankless(l, r, max) - wl.rangerankless(l, r, min)
}






Measured memory_bytes: 136400