class Node
  attr_accessor :pos, :num, :left, :right
  def initialize(pos, num)
    @pos = pos
    @num = num
    @left = nil
    @right = nil
  end
end

def addnode(tree, pos, num, depth)
  if tree == nil then
    tree = Node.new(pos, num)
    return tree
  end
  k = pos.size
  axis = depth % k

  if tree.pos[axis] > pos[axis]
    tree.left = addnode(tree.left, pos, num, depth+1)
  else
    tree.right = addnode(tree.right, pos, num, depth+1)
  end
  return tree
end

def kdtree(arr, depth)
  return nil if arr.size == 0
  k = arr[0].size - 1
  axis = depth % k

  sorted = arr.sort_by{|x| x[axis]}
#  p arr
  median = sorted.size / 2

  node = Node.new(sorted[median][0,k], sorted[median][k])
  node.left = kdtree(sorted[0,median], depth+1)
  node.right = kdtree(sorted[median+1..-1], depth+1)
  return node
end

def range_search(tree, s, t, depth)
  return [] unless tree
  axis = depth % s.size
  ans = []
  flag = true
  s.size.times{|i|
    unless s[i] <= tree.pos[i] && tree.pos[i] <= t[i]
      flag = false
      break
    end
  }
  ans << tree.num if flag
  ans += range_search(tree.left, s, t, depth+1) if s[axis] <= tree.pos[axis]
  ans += range_search(tree.right, s, t, depth+1) if tree.pos[axis] <= t[axis]
  return ans
end

arr = []
n = gets.to_i

tree = nil
n.times{|i|
  arr[i] = gets.split.map(&:to_i)
  arr[i] << i
}

tree = kdtree(arr, 0)

q = gets.to_i

q.times{
  sx, tx, sy, ty = gets.split.map(&:to_i)
  ans = range_search(tree, [sx, sy], [tx, ty],  0)
  ans.sort.each{|i|
    puts i
  }
  puts
}