#include <bits/stdc++.h>
using namespace std;
map<string, string> m;
string trans(string a) {
  int i, j, cnt = 0;
  for (i = 0; i < ((int)(a).size()) && a[i] == '&'; i++)
    ;
  for (j = i; j < ((int)(a).size()) && a[j] != '*'; j++)
    ;
  string s = m[a.substr(i, j - i)];
  if (s == "" || s == "errtype") return "errtype";
  a = a.replace(i, j - i, s);
  for (int i = 0; i < ((int)(a).size()); i++) {
    if (a[i] == '&') --cnt;
    if (a[i] == '*') ++cnt;
  }
  if (cnt < 0) return "errtype";
  s = "void";
  for (int i = 0; i < cnt; i++) s += "*";
  return s;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  m["void"] = "void";
  m["errtype"] = "errtype";
  int n;
  cin >> n;
  string w, a, b;
  for (int i = 0; i < n; i++) {
    cin >> w;
    if (w == "typeof") {
      cin >> a;
      cout << trans(a) << "\n";
    } else {
      cin >> a >> b;
      m[b] = trans(a);
    }
  }
  return 0;
}
