#include <bits/stdc++.h>

using namespace std;
#define rep_i(i, n) for (int i = 0; i < (n); ++i)
#define rep_ll(i, n) for (long long i = 0; i < (n); ++i)
#define r_rep_i(i, start, end) for (int i = (start); i < (end); ++i)
#define r_rep_ll(i, start, end) for (long long i = (start); i < (end); ++i)
#define debug_vi(v) copy((v).begin(), (v).end(), ostream_iterator<int>(cout, " "));
#define debug_vll(v) copy((v).begin(), (v).end(), ostream_iterator<long long>(cout, " "));
#define debug_vd(v) copy((v).begin(), (v).end(), ostream_iterator<double>(cout, " "));
#define sort_v(v) sort((v).begin(), (v).end()); //昇順
#define d_sort_vi(v) sort((v).begin(), (v).end(), greater<int>()); //降
#define d_sort_vd(v) sort((v).begin(), (v).end(), greater<double>()); //昇順
#define say(t) cout << (t) << endl;
#define sum_vi(v) accumulate((v).begin(), (v).end(), 0);
#define sum_vll(v)accumulate((v).begin(), (v).end(), 0LL);

int main(){
  int n, q;
  cin >> n >> q;
  vector< list<int> > v(n);
  rep_i(i, n){
    list<int> a;
    v.push_back(a);
  }

  int tmp, tmp2, tmp3;
  rep_i(i, q){
    cin >> tmp;
    switch (tmp)
    {
    case 0:
      cin >> tmp2 >> tmp3;
      v[tmp2].push_back(tmp3);
      break;
    case 1:
      cin >> tmp2;
      if(v[tmp2].empty()){
        cout << endl;
        break;
      }

      for (list<int>::iterator i = v[tmp2].begin(); i != v[tmp2].end(); i++){
        if(i == --v[tmp2].end()){
          say(*i);
        }else{
          cout << *i << " ";
        }
      }
      
      // rep_i(i, v[tmp2].size()){
      //   if(i == v[tmp2].size() - 1){
      //     say(v[tmp2][i]);
      //   }else{
      //     cout << v[tmp2][i] << " ";
      //   }
      // }
      // say(v[tmp2].top());
      break;
    case 2:
      cin >> tmp2 >> tmp3;
      // これだと制限時間に間に合わなため、splintを使用する必要がある
      // v[tmp3].insert(v[tmp3].end(), v[tmp2].begin(), v[tmp2].end());
      // v[tmp2].clear();
      v[tmp3].splice(v[tmp3].end(), v[tmp2]);
      break;
    default:
      break;
    }
  }
}
