#include <bits/stdc++.h>
using namespace std;
map<string, int> M;
int countAmp(string s) {
  int i = 0;
  while (s[i] == '&') ++i;
  return i;
}
int countAst(string s) {
  int n = s.size();
  int i = n - 1;
  while (s[i] == '*') --i;
  return n - 1 - i;
}
int main() {
  M.clear();
  M["void"] = 0;
  M["errtype"] = -1;
  int n;
  scanf("%d\n", &n);
  string s, s1, s2;
  while (n--) {
    cin >> s;
    if (s == "typedef") {
      cin >> s1 >> s2;
      int i = countAst(s1);
      int j = countAmp(s1);
      int k;
      s1 = s1.substr(j, int(s1.size()) - i - j);
      if (!M.count(s1))
        k = -1;
      else {
        k = M[s1];
        if (k >= 0) k += i;
        k -= j;
        if (k < 0) k = -1;
      }
      M[s2] = k;
    } else {
      cin >> s1;
      int x;
      int i = countAst(s1);
      int j = countAmp(s1);
      s1 = s1.substr(j, int(s1.size()) - i - j);
      if (!M.count(s1))
        x = -1;
      else {
        x = M[s1];
        if (x >= 0) x += i;
        x -= j;
      }
      if (x < 0)
        puts("errtype");
      else {
        printf("void");
        while (x--) putchar('*');
        puts("");
      }
    }
  }
  return 0;
}
