n, q = gets.chomp.split(" ").map &:to_i

A=[]
n.times{
    A.push([])
}

q.times{
    choice, t, x = gets.chomp.split(" ").map &:to_i
    case choice
    when 0
        A[t].push(x)
    when 1
        puts A[t].join(' ')
    when 2 
        A[x].push(*A[t])
        A[t].clear
    end
}
