#include<iostream>
#include<set>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int n;
string s;
vector<string> file;
vector<string> substr(string st) {
vector<string> t;
string l = "";
int len = (int)(st.length());
for (int i = 0; i < len; i++) {
if (st[i] == ' ') {
t.push_back(l);
l = "";
}
else {
l += st[i];
}
}
t.push_back(l);
return t;
}
int main()
{
cin >> n;
getchar();
for (int i = 0; i < n; i++) {
getline(cin, s);
vector<string> t = substr(s);
if (t[0] == "touch") {
auto id = find(file.begin(), file.end(), t[1]);
if (id == file.end())
file.push_back(t[1]);
}
else if (t[0] == "rename") {
auto id1 = find(file.begin(), file.end(), t[1]);
auto id2 = find(file.begin(), file.end(), t[2]);
if (id2 == file.end() && id1 != file.end()) {
*(id1) = t[2];
}
}
else if (t[0] == "rm") {
auto id = find(file.begin(), file.end(), t[1]);
if (id != file.end())
file.erase(id);
}
else if (t[0] == "ls") {
for (auto i : file) {
cout << (i) << endl;
}
}
}
return 0;
}