#include <stdio.h>
#include<vector>
#include<iostream>
#include<string>
#include<deque>
#include<queue>
#include<stack>
#include<list>
using namespace std;


int main() {
	list<int> arr[1000];
	list<int>::iterator itr;
	int n, q, t, x;
	int query;
	cin >> n >> q;
	for (int i = 0; i < q; i++)
	{
		cin >> query >> t;
		switch (query)
		{
		case 0:
			cin >> x;
			arr[t].push_back(x);
			break;
		case 1:
			for (itr = arr[t].begin(); itr != arr[t].end(); itr++)
			{
				if (itr != arr[t].begin())cout << " ";
				cout << *itr;
			}
			cout << endl;
			break;
		case 2:
			cin >> x;
			arr[x].splice(arr[x].end(), arr[t]);
			break;
		}
	}


	return 0;
}
