#include <bits/stdc++.h>
using namespace std;
string na[1001];
int n, f[1001];
int top;
char nam[1001];
char s[1001];
inline int getind(char *s) {
  for (int i = 0; i <= top; ++i)
    if (strcmp(na[i].c_str(), s) == 0) return i;
  na[++top] = s;
  f[top] = -1;
  return top;
}
int main() {
  na[0] = "void", f[0] = 0;
  na[1] = "errtype", f[1] = -1;
  top = 1;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%s", s);
    if (s[4] == 'd') {
      scanf("%s", s);
      int l = 0, cnt = 0;
      while (s[l] == '&') l++, cnt--;
      int r = strlen(s) - 1;
      while (s[r] == '*') r--, cnt++;
      s[r + 1] = 0;
      int p = getind(s + l);
      if (f[p] < 0)
        cnt = -1;
      else
        cnt += f[p];
      scanf("%s", nam);
      p = getind(nam);
      f[p] = cnt;
    } else {
      scanf("%s", s);
      int l = 0, cnt = 0;
      while (s[l] == '&') l++, cnt--;
      int r = strlen(s) - 1;
      while (s[r] == '*') r--, cnt++;
      s[r + 1] = 0;
      int p = getind(s + l);
      if (f[p] < 0)
        cnt = -1;
      else
        cnt += f[p];
      if (cnt < 0)
        printf("errtype\n");
      else {
        printf("void");
        for (int j = 1; j <= cnt; ++j) printf("*");
        printf("\n");
      }
    }
  }
  return 0;
}
