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 range_search(tree, r, depth)
  it = depth % 2
  ans = []
  if 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*it] <= tree.p[it]
    ans += range_search(tree.left, r, depth+1)
  end
  if tree.right && tree.p[it] <= r[2*it+1]
    ans += range_search(tree.right, r, depth+1)
  end
  return ans
end

arr = []
n = gets.to_i

tree = nil
n.times{|i|
  arr[i] = gets.split.map(&:to_i)
  arr[i] << i
}
# to make low-height 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
}