#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
const long long INFLL = 1LL << 60;
const int INFINT = 1 << 30;
const long long MOD = 1e9 + 7;

template <class T> void vecout(T V) {
    auto t = V.begin();
    while(t != V.end()) {
        cout << *t++;
        if(t != V.end()) cout << " ";
    }
    cout << endl;
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, Q, q, s, t, x;
    cin >> n >> Q;
    list<int> v[n];

    rep(i, Q) {
        cin >> q;
        if(q == 0) {
            cin >> t >> x;
            v[t].push_back(x);
        } else if(q == 1) {
            cin >> t;
            vecout(v[t]);
        } else {
            cin >> s >> t;
            v[t].splice(v[t].end(), v[s]);
        }
    }
}

