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
  attr_accessor :left, :right
  def initialize(point)
    @point = point
  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)
    node = Node.new(point)
    @nodes << node
    return if root == node

    parent = root
    depth = 0
    loop do
      method = depth.even? ? :x : :y
      if point.send(method) < parent.point.send(method)
        unless parent.left
          parent.left = node
          break
        end
        parent = parent.left
      else
        unless parent.right
          parent.right = node
          break
        end
        parent = parent.right
      end
    end
  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.first
  end
end

tree = TDTree.new
points = []

n = gets.to_i
n.times do |i|
  points << Point.new(i, *gets.split.map(&:to_i))
end
points.shuffle.each do |point|
  tree.add_point(point)
end

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

