#include<iostream>
#include<list>
using namespace std;
int main()
{
  int n,f,q,t,x,s;
  cin>>n>>q;
  list<int>L[n];
  list<int>::iterator it;
  while(q--)
{
    cin>>f;
    switch(f)
 {
  case 0:
            cin>>t>>x;
            L[t].push_back(x);
            break;
  case 1:
            cin>>t;
            for(it=L[t].begin(); it !=L[t].end(); it++){
            if(it!=L[t].begin())
              cout<<' ';
              cout<<*it;
            }

            cout<<endl;
            break;
  case 2:
            cin>>s>>t;
            if(! L[s].empty())
            L[t].splice(L[t].end(),L[s]);
            break;

 }

}

  return 0;
}

