#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
#include <stack>
#include<queue>
#include<list>

using std::vector;

int main()
{
    int n,q,ope,t,x,s;
    std::cin>>n>>q;
    std::list<int> S[n];

    for(int i = 0; i < q; i++)
    {
        std::cin>>ope;
        if(ope==0){std::cin>>t>>x;S[t].push_back(x);}
        else if(ope==1){std::cin>>t;      
        for(std::list<int>::iterator it = S[t].begin();it != S[t].end();it++){
        if(it != S[t].begin()) std::cout << " ";
        std::cout<<*it;}
        std::cout<<std::endl;
        }
        else{ std::cin>>s>>t; S[t].splice(S[t].end(), S[s]);}
    }

    return 0;
}

