#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  map<string, int> vars;
  vars["void"] = 0;
  vars["errtype"] = -1000000;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string op;
    cin >> op;
    if (op == "typedef") {
      string exp, var, expvar;
      cin >> exp >> var;
      int it = 0, asts = 0;
      while (exp[it] == '&') {
        it++;
        asts--;
      }
      while (exp[it] != '*' && it < exp.size()) {
        expvar += exp[it];
        it++;
      }
      if (vars.find(expvar) == vars.end()) {
        asts = -100000;
      } else if (vars[expvar] < 0) {
        asts = -100000;
      } else {
        asts += vars[expvar];
      }
      while (exp[it] == '*' && it < exp.size()) {
        it++;
        asts++;
      }
      vars[var] = asts;
    } else {
      string exp, expvar;
      cin >> exp;
      int it = 0, asts = 0;
      while (exp[it] == '&') {
        it++;
        asts--;
      }
      while (exp[it] != '*' && it < exp.size()) {
        expvar += exp[it];
        it++;
      }
      if (vars.find(expvar) == vars.end()) {
        asts = -100000;
      } else if (vars[expvar] < 0) {
        asts = -100000;
      } else {
        asts += vars[expvar];
      }
      while (exp[it] == '*' && it < exp.size()) {
        it++;
        asts++;
      }
      if (asts < 0) {
        cout << "errtype" << endl;
      } else {
        cout << "void";
        for (int j = 0; j < asts; j++) {
          cout << "*";
        }
        cout << endl;
      }
    }
  }
}
