#include <bits/stdc++.h>
struct str {
  char s[100];
  void set(char *ss, int l, int r) {
    for (int i = l; i <= r; i++) {
      s[i - l] = ss[i];
    }
    s[r - l + 1] = 0;
    s[r - l + 2] = 100;
  }
  bool operator<(const str &b) const {
    for (int i = 0; b.s[i] + s[i]; i++) {
      if (b.s[i] != s[i]) return s[i] < b.s[i];
    }
    return false;
  }
} tmp, t2;
std::map<str, int> conv, app;
int N;
char s1[1000], s2[1000], s3[1000];
char vv[100] = "errtype", v2[100] = "void";
int main() {
  scanf("%d", &N);
  tmp.set(vv, 0, 6);
  conv[tmp] = -1;
  app[tmp] = 1;
  tmp.set(v2, 0, 3);
  conv[tmp] = 0;
  app[tmp] = 1;
  for (int i = 0; i < N; i++) {
    scanf("%s", s1);
    if (s1[4] == 'd') {
      scanf("%s%s", s2, s3);
      int s2l = strlen(s2);
      int s3l = strlen(s3);
      int l = 0, r = s2l - 1, lc = 0, rc = 0;
      for (; s2[l] == '&'; l++) lc++;
      for (; s2[r] == '*'; r--) rc++;
      tmp.set(s2, l, r);
      t2.set(s3, 0, s3l - 1);
      if (conv[tmp] < 0)
        conv[t2] = -1;
      else
        conv[t2] = conv[tmp] + rc - lc;
      app[t2] = app[tmp];
    } else {
      scanf("%s", s2);
      int s2l = strlen(s2);
      int l = 0, r = s2l - 1, lc = 0, rc = 0;
      for (; s2[l] == '&'; l++) lc++;
      for (; s2[r] == '*'; r--) rc++;
      tmp.set(s2, l, r);
      int val = conv[tmp] + rc - lc;
      if (val < 0 || conv[tmp] < 0 || app[tmp] == 0)
        puts("errtype");
      else {
        printf("void");
        for (int i = val; i > 0; i--) putchar('*');
        puts("");
      }
    }
  }
}
