#include <bits/stdc++.h>
using namespace std;
struct node {
  int a;
  string type;
  node() {}
  node(int x, const char *s) {
    a = x;
    type = s;
  }
};
map<string, node> h;
char str[100];
int main() {
  int n;
  scanf("%d", &n);
  char a[100], b[100];
  int x, y;
  h["void"] = node(0, "void");
  for (int i = 1; i <= n; i++) {
    scanf("%s", str);
    if (strcmp(str, "typedef") == 0) {
      scanf("%s %s", a, b);
      x = y = 0;
      int j = 0;
      while (a[j] == '&') j++, x++;
      j = strlen(a) - 1;
      while (a[j] == '*') j--, y++;
      a[j + 1] = 0;
      node tmp;
      if (h.find(a + x) == h.end()) {
        tmp = node(0, "errtype");
      } else
        tmp = h[a + x];
      x -= y;
      tmp.a += x;
      if (tmp.a > 0) {
        tmp.type = "errtype";
      }
      h[b] = tmp;
    } else {
      scanf("%s", a);
      x = y = 0;
      int j = 0;
      while (a[j] == '&') j++, x++;
      j = strlen(a) - 1;
      while (a[j] == '*') j--, y++;
      a[j + 1] = 0;
      node t;
      if (h.find(a + x) == h.end()) {
        t = node(0, "errtype");
      } else
        t = h[a + x];
      x -= y;
      t.a += x;
      if (t.a > 0) {
        cout << "errtype" << endl;
      } else {
        cout << t.type;
        if (t.type != "errtype") {
          for (int i = 1; i <= -t.a; i++) putchar('*');
        }
        puts("");
      }
    }
  }
  return 0;
}
