#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = 1ll << 60;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s, f) cout << fixed << setprecision(f) << s << endl;


int main()
{
	int n, m;
	cin >> n >> m;

	vector<list<int>> a(n);

	for (int i = 0; i < m; i++)
	{
		int q, t, x;
		cin >> q >> t;

		bool sp = false;

		switch (q)
		{
			case 0:
				cin >> x;
				a[t].push_back(x);
				break;

			case 1:
				for (int j : a[t])
				{
					print((sp ? " " : "") << j);
					sp = true;
				}
				println("");
				break;

			case 2:
				cin >> x;
				a[x].splice(a[x].end(), move(a[t]));
				break;
		}
	}
}
