nq = gets.split.map(&:to_i)
ary = Array.new(nq[0]){[]}

nq[1].times do
  odr = gets.split.map(&:to_i)
  case odr[0]
  when 0
      ary[odr[1]] << odr[2]
  when 1
      puts(ary[odr[1]].join(" "))
  when 2
      ary[odr[1]].each do |value|
        ary[odr[2]] << value
      end
      ary[odr[1]].clear
  end
end

