#include <bits/stdc++.h>
using namespace std;
template <typename Tk, typename Tv>
ostream& operator<<(ostream& os, const pair<Tk, Tv>& p) {
  os << "{" << p.first << ',' << p.second << "}";
  return os;
}
const int MAX = 100005;
const int MOD = 1000000000 + 7;
const int INF = 1000000000;
pair<string, int> extract(string s) {
  int count = 0;
  int i = 0;
  for (; (s[i] == '&') && i < s.size(); i++) {
    count--;
  }
  string t = "";
  for (; (s[i] >= 'a' && s[i] <= 'z') && i < s.size(); i++) {
    t.push_back(s[i]);
  }
  for (; s[i] == '*' && i < s.size(); i++) {
    count++;
  }
  return make_pair(t, count);
}
int main() {
  int n;
  scanf("%d", &n);
  map<string, int> M;
  for (int i = 0; i < n; i++) {
    string type;
    cin >> type;
    if (type == "typedef") {
      string a, b;
      cin >> a >> b;
      pair<string, int> g = extract(a);
      pair<string, int> r = extract(b);
      if (M.count(g.first)) {
        if (M[g.first] == INF) {
          M[r.first] = INF;
        } else {
          int count = M[g.first] + g.second;
          if (count >= 0) {
            M[r.first] = count;
          } else {
            M[r.first] = INF;
          }
        }
      } else if (g.first == "void") {
        if (g.second >= 0) {
          M[r.first] = g.second;
        } else {
          M[r.first] = INF;
        }
      } else {
        M[r.first] = INF;
      }
    } else {
      string a;
      cin >> a;
      pair<string, int> r = extract(a);
      if (a == "void") {
        cout << "void" << endl;
      } else if (M.count(r.first)) {
        if (r.second == INF) {
          cout << "errtype" << endl;
        } else {
          int count = M[r.first] + r.second;
          if (M[r.first] == INF) {
            cout << "errtype" << endl;
          } else if (count >= INF) {
            cout << "errtype" << endl;
          } else {
            if (count >= 0) {
              cout << "void";
              for (int i = 0; i < count; i++) {
                cout << "*";
              }
              cout << endl;
            } else {
              cout << "errtype" << endl;
            }
          }
        }
      } else {
        cout << "errtype" << endl;
      }
    }
  }
}
