#include <bits/stdc++.h>
using namespace std;
map<string, int> m;
int n;
int eval(string s) {
  int c1 = 0, c2 = 0;
  string t = "";
  int ind1 = 0, ind2 = s.size() - 1;
  while (ind1 < s.size() && s[ind1] == '&') ++ind1, ++c1;
  while (ind2 >= 0 && s[ind2] == '*') --ind2, ++c2;
  t = s.substr(ind1, ind2 - ind1 + 1);
  if (!m.count(t)) return -1;
  int x = m[t];
  if (x == -1) return -1;
  x += c2 - c1;
  if (x < 0) return -1;
  return x;
}
int main() {
  cin >> n;
  m["void"] = 0;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    if (s == "typedef") {
      string l, t;
      cin >> l >> t;
      m[t] = eval(l);
    } else if (s == "typeof") {
      string t;
      cin >> t;
      int x = eval(t);
      if (x == -1)
        cout << "errtype";
      else
        cout << "void";
      for (int j = 0; j < x; j++) cout << '*';
      cout << endl;
    }
  }
  return 0;
}
