N = gets.to_i R = N.times.map { gets.split.map(&:to_i) } ans = [] queue = [] R.each do |cnt, *a| next if cnt == 0 queue << a end until queue.empty? list = queue.shift id = list.shift ans << id next if list.empty? queue << list end puts ans.join(' ')