n, q = gets.chomp.split.map(&:to_i)
h = []
count = Array.new(n-1, 0)
(n-1).times do |i|
  h[i] = gets.chomp.split.map(&:to_i)
end
a = Array.new(n, [])
(n-1).downto(0) do |i|
  a[i].push(i)
  (i-1).downto(0) do |t|
    if h[t][0] == i
      a[i].push(t)
    end
  end
end
p a
o = []
q.times do |i|
  o[i] = gets.chomp.split.map(&:to_i)
end
