class Point
  attr_reader :id, :x, :y
  def initialize(id, x, y)
    @id = id
    @x = x
    @y = y
  end
end

class Node
  attr_reader :point, :left, :right
  def initialize(point, left, right)
    @point = point
    @left = left
    @right = right
  end
end

class XYRange
  attr_reader :sx, :tx, :sy, :ty
  def initialize(sx, tx, sy, ty)
    @sx, @tx, @sy, @ty = sx, tx, sy, ty
  end

  def member?(point)
    sx <= point.x && point.x <= tx &&
      sy <= point.y && point.y <= ty
  end
end

class TDTree
  def initialize
    @points = []
    @nodes = []
  end

  def add_point(point)
    @points << point
  end

  def build(left = 0, right = @points.length, depth = 0)
    return if left >= right
    middle = (left + right) / 2

    method = depth.even? ? :x : :y
    @points[left...right] = @points[left...right].sort_by(&method)

    Node.new(
      @points[middle],
      build(left, middle, depth + 1),
      build(middle + 1, right, depth + 1)
    ).tap { |n| @nodes << n }
  end

  def search(range, node = root, depth = 0, results = [])
    point = node.point
    if range.member?(point)
      results << point
    end

    if depth.even?
      if node.left && range.sx <= point.x
        search(range, node.left, depth + 1, results)
      end
      if node.right && point.x <= range.tx
        search(range, node.right, depth + 1, results)
      end
    else
      if node.left && range.sy <= point.y
        search(range, node.left, depth + 1, results)
      end
      if node.right && point.y <= range.ty
        search(range, node.right, depth + 1, results)
      end
    end

    results.tap { |r| r.sort_by!(&:id) if depth == 0 }
  end

  def root
    @nodes.last
  end
end

tree = TDTree.new

n = gets.to_i
n.times do |i|
  tree.add_point(Point.new(i, *gets.split.map(&:to_i)))
end
tree.build

q = gets.to_i
q.times do
  range = XYRange.new(*gets.split.map(&:to_i))
  tree.search(range).each { |point| puts point.id }
  puts
end

