#include <bits/stdc++.h>
using namespace std;
void strip(string& str, int& acount, int& scount) {
  acount = scount = 0;
  for (int i = 0; str[i] == '&'; ++i) ++acount;
  str.erase(0, acount);
  for (int i = (int)str.length() - 1; str[i] == '*'; --i) ++scount;
  str.erase(str.length() - scount, scount);
}
int main() {
  int n, acount, scount;
  map<string, int> types;
  string type, str, newtype;
  cin >> n;
  while (n--) {
    cin >> str >> type;
    strip(type, acount, scount);
    if (str == "typedef") {
      cin >> newtype;
      if (type == "errtype" || (type == "void" && scount - acount < 0) ||
          (type != "void" && types.find(type) == types.end()) ||
          (types.find(type) != types.end() &&
           (types[type] == -1 || scount + types[type] - acount < 0))) {
        types[newtype] = -1;
      } else {
        types[newtype] = scount + types[type] - acount;
      }
    } else {
      if (type == "errtype" || (type == "void" && scount - acount < 0) ||
          (type != "void" && types.find(type) == types.end()) ||
          (types.find(type) != types.end() &&
           (types[type] == -1 || scount + types[type] - acount < 0))) {
        cout << "errtype\n";
      } else {
        cout << "void";
        scount = scount + types[type] - acount;
        while (scount--) cout << "*";
        cout << "\n";
      }
    }
  }
  return 0;
}
