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

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

#   if tree.p[axis] > p[axis]
#     tree.left = addnode(tree.left, p, num, depth+1)
#   else
#     tree.right = addnode(tree.right, p, 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]}
  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, r, depth)
  return [] unless tree
  axis = depth % 2
  ans = []
  ans << tree.num if r[0] <= tree.p[0] && tree.p[0] <= r[1] && r[2] <= tree.p[1] && tree.p[1] <= r[3]
  ans += range_search(tree.left, r, depth+1) if tree.left && r[2*axis] <= tree.p[axis]
  ans += range_search(tree.right, r, depth+1) if tree.right && tree.p[axis] <= r[2*axis+1]
  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{
  range_search(tree, gets.split.map(&:to_i),  0).sort.each{|i|
    puts i
  }
  puts
}