#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)

using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;

void dump(list<int> l) {
    list<int>::iterator it = l.begin();
    if (it != l.end()) {
        cout<<*it;
        it++;
        while (it != l.end()) {
            cout<<" "<<*it;
            it++;
        }
    }
    cout<<endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, q;
    cin>>n>>q;
    vector<list<int>> ls(n);
    rep(i, q) {
        int j, t, x;
        cin>>j>>t;
        if (j == 0) {
            cin>>x;
            ls[t].insert(ls[t].end(), x);
        }
        else if (j == 1) {
            dump(ls[t]);
        }
        else {
            cin>>x;
            list<int>::iterator it = ls[x].end();
            ls[x].splice(it, ls[t]);
            ls[t].clear();
        }
    }
}
