#include<iostream>#include<cstring>#include<set>#include<vector>#include<string>#include<map>#define MAXN 100010using namespace std;int tot;string dic[MAXN];map<string, int> mymap;set<string> method[MAXN];int pre[MAXN];int main() {int T;int i;cin >> T;string cmd;string str, son, father;string cla, met;while (T--) {tot = 0;mymap.clear();for (i = 0; i < MAXN; i++) {method[i].clear();}memset(pre, -1, sizeof(pre));while (cin >> cmd, cmd != "end") {if (cmd == "begin") {continue;} else if (cmd == "class") {cin >> str;son.clear();father.clear();for (i = 0; i < (int) str.length(); i++) {if (str[i] == ':') {break;}son.push_back(str[i]);}for (i++; i < (int) str.length(); i++) {father.push_back(str[i]);}if (!mymap.count(son)&& (!father.size()|| (father.size() && mymap.count(father)))) {cout << "class " << str << endl;mymap[son] = ++tot;dic[tot] = son;if (father.size()) {pre[tot] = mymap[father];}} else {cout << "oops!" << endl;}} else if (cmd == "def") {cla.clear();met.clear();cin >> str;for (i = 0; i < (int) str.length(); i++) {if (str[i] == '.') {break;}cla.push_back(str[i]);}for (i++; i < (int) str.length(); i++) {met.push_back(str[i]);}if (!mymap.count(cla)) {cout << "oops!" << endl;} else {if (method[mymap[cla]].count(met)) {cout << "redef " << str << endl;} else {cout << "def " << str << endl;method[mymap[cla]].insert(met);}}} else if (cmd == "undef") {cla.clear();met.clear();cin >> str;for (i = 0; i < (int) str.length(); i++) {if (str[i] == '.') {break;}cla.push_back(str[i]);}for (i++; i < (int) str.length(); i++) {met.push_back(str[i]);}if (mymap.count(cla) && method[mymap[cla]].count(met)) {method[mymap[cla]].erase(method[mymap[cla]].find(met));cout << "undef " << str << endl;} else {cout << "oops!" << endl;}} else if (cmd == "call") {cla.clear();met.clear();cin >> str;for (i = 0; i < (int) str.length(); i++) {if (str[i] == '.') {break;}cla.push_back(str[i]);}for (i++; i < (int) str.length(); i++) {met.push_back(str[i]);}if (mymap.count(cla)) {i = mymap[cla];for (; i != -1; i = pre[i]) {if (method[i].count(met)) {break;}}if (i == -1) {cout << "oops!" << endl;} else {cout << "invoke " << dic[i] << "." << met << endl;}} else {cout << "oops!" << endl;}}}cout << endl;}return 0;}


