class Node
  attr_accessor :p, :num, :left, :right, :max, :min
  def initialize(p, num)
    @p = p
    @num = num
    @left = nil
    @right = nil
    @max = [p[0], p[1]]
    @min = [p[0], p[1]]
  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
  2.times{|i|
    tree.max[i] = p[i] if tree.max[i] < p[i]
    tree.min[i] = p[i] if tree.min[i] > p[i]
  }
  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
#   min = sorted[0][axis]
#   max = sorted[-1][axis]
#   node = Node.new(sorted[median][0,k], sorted[median][k], max, min)
#   node.left = kdtree(sorted[0,median], depth+1)
#   node.right = kdtree(sorted[median+1..-1], depth+1)
#   return node
# end

def check(p, r)
  if r[0] <= p[0] && p[0] <= r[1] && r[2] <= p[1] && p[1] <= r[3] then
    return true
  else
    return false
  end
end

def check2(n, r)
  if r[0] <= n.max[0] && n.min[0] <= r[1] then
    return true
  else
    return false
  end
end
def range_search(tree, r)
  return [] unless tree
  ans = []
  ans << tree.num if check(tree.p, r)
  ans += range_search(tree.left,  r) if tree.left  && check2(tree.left, r)
  ans += range_search(tree.right, r) if tree.right && check2(tree.right, r)
  # ans += range_search(tree.left,  r) if tree.left
  # ans += range_search(tree.right, r) if tree.right
  return ans
end

arr = []
n = gets.to_i

tree = nil
n.times{|i|
  arr[i] = gets.split.map(&:to_i)
  arr[i] << i
}


arr.shuffle.each{|i|
  tree = addnode(tree, i[0,2], i[2], 0)
}
# tree = kdtree(arr, 0)

q = gets.to_i

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