#include <iostream>
#include <string>
#include <list>
using namespace std;
list<int> no;
int getIndex(int id) {
int res=0;
list<int>::iterator ii;
for (ii = no.begin();ii != no.end();++ii) {
if (id == *ii) {
return res;
}
++res;
}
}
int main() {
int line,ino=0;
cin >> line;
list<int> lst[200];
//cout << sizeof(line);
string cmd;
for (int i = 0;i < line;++i) {
cin >> cmd;
if (cmd == "new") {
int id;
cin >> id;
no.push_back(id);
//cout << cmd << " " << id;
}
if (cmd == "add") {
int id,val;
cin >> id >>val;
lst[getIndex(id)].push_back(val);
//cout << cmd << " " << id << " " << val;
}
if (cmd == "merge") {
int id1, id2;
cin >> id1 >> id2;
lst[getIndex(id1)].merge(lst[getIndex(id2)]);
}
if (cmd == "out") {
int id;
cin >> id;
lst[getIndex(id)].sort();
ostream_iterator<int> output(cout, " ");
copy(lst[getIndex(id)].begin(), lst[getIndex(id)].end(), output);
cout << endl;
}
if (cmd == "unique") {
int id;
cin >> id;
lst[getIndex(id)].sort();
lst[getIndex(id)].unique();
}
}
return 0;
}