#include <iostream>
#include <vector>
#include <list>
using namespace std;

#define lint list<int>

int main() {
	vector<lint> vec; int an, tn, fn1, fn2, fn3, en, set;
	cin >> an >> tn; vec.resize(an);
	for (int i = 0; i < tn; i++) {
		cin >> fn1;
		switch (fn1) {
		case 0: cin >> fn2 >> en; vec[fn2].push_back(en); break;
		case 1: cin >> fn2; set = 0;
			for (int i : vec[fn2]) cout << (set++ ? " " : "") << i;
			cout << endl; break;
		case 2: cin >> fn2 >> fn3; 
			vec[fn3].splice(vec[fn3].end(), vec[fn2]); break;
		}
	}
	return 0;
}
