#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <list>

#define INPUT_FROM_FILE (0) 
#if INPUT_FROM_FILE
#include <fstream>
#endif

int main(int argc, char **argv){
	int n , q;
	std::string buf;
	std::vector<std::list<long> > lists;

#if INPUT_FROM_FILE
	std::ifstream ifs("test.txt");
	//FILE *fp = fopen("test.txt", "r");
#endif


#if INPUT_FROM_FILE
	std::getline(ifs, buf);
#else
	std::getline(std::cin, buf);
#endif
	{
		std::istringstream stream(buf);

		stream >> n >> q;
	}

	lists.resize(n);
	for(int i = 0; i < q; i++){
#if INPUT_FROM_FILE
		std::getline(ifs, buf);
#else
		std::getline(std::cin, buf);
#endif
		std::istringstream stream(buf);
		long tmp, s, t, x;

		if(buf[0] == '0'){
			stream >> tmp >> t >> x;

			lists[t].push_back(x);
		}
		else if(buf[0] == '1'){
			stream >> tmp >> t;

			if(lists[t].empty()){
				std::cout << std::endl;
			}
			else{
				std::cout << lists[t].front();
				std::list<long>::const_iterator it = lists[t].begin();
				it++;
				for(; it != lists[t].end(); it++){
					std::cout << " " << *it;
				}
				std::cout << std::endl;
			}
		}
		else{
			stream >> tmp >> s >> t;
			lists[t].splice(lists[t].end(), lists[s]);
		}

	}

	return 0;
}

