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, axis)
  if tree == nil then
    tree = Node.new(p, num)
    return tree
  end
  axis ^= 1 # swap axis

  if tree.p[axis] > p[axis]
    tree.left = addnode(tree.left, p, num, axis)
  else
    tree.right = addnode(tree.right, p, num, axis)
  end
  return tree
end

def range_search(tree, r, axis)
  axis ^= 1 # swap asis
  ans = []
  unless r[0] > tree.p[0] || tree.p[0] > r[1] || r[2] > tree.p[1] || tree.p[1] > r[3]
    ans << tree.num
  end
  if tree.left && r[2*axis] <= tree.p[axis]
    ans += range_search(tree.left, r, axis)
  end
  if tree.right && tree.p[axis] <= r[2*axis+1]
    ans += range_search(tree.right, r, axis)
  end
  return ans
end

n = gets.to_i
arr = Array.new(n){[]}

tree = nil
n.times{|i|
  arr[i] = gets.split.map(&:to_i)
  arr[i] << i
}
# to make semi-balanced tree
arr.shuffle.each{|i|
  tree = addnode(tree, i[0,2], i[2], 0)
}

q = gets.to_i

q.times{
  range_search(tree, gets.split.map(&:to_i),  0).sort.each{|i|
    puts i
  }
  puts
}