#include <bits/stdc++.h>
using namespace std;
map<string, string> m;
string get_type(const string& type) {
  if (type == "void") return "void";
  if (type == "errtype") return "errtype";
  if (m.count(type)) return m[type];
  return "errtype";
}
string ref(const string& s) {
  if (s == "errtype") return "errtype";
  return s + "*";
}
string unref(const string& s) {
  if (s == "errtype") return "errtype";
  if (s[s.size() - 1] == '*') return s.substr(0, s.size() - 1);
  return "errtype";
}
string parse(const string& s) {
  int rp = s.size() - 1;
  int dp = 0;
  while (s[dp] == '&') dp++;
  while (s[rp] == '*') rp--;
  int nd = dp;
  int nr = s.size() - rp - 1;
  string type = s.substr(dp, rp - dp + 1);
  type = get_type(type);
  for (int i = 0; i < nr; ++i) type = ref(type);
  for (int i = 0; i < nd; ++i) type = unref(type);
  return type;
}
int main() {
  int n;
  while (cin >> n) {
    for (int i = 0; i < n; ++i) {
      string com;
      cin >> com;
      if (com == "typeof") {
        string s;
        cin >> s;
        cout << parse(s) << endl;
      } else if (com == "typedef") {
        string a, b;
        cin >> a >> b;
        string res = parse(a);
        m[b] = res;
      }
    }
  }
}
