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