#include <bits/stdc++.h>
struct Type {
  char c[40];
  void clear() {
    memset(c, 0, sizeof(c));
    return;
  }
  bool operator<(const Type &cmp) const {
    int k = 0;
    for (; c[k] && cmp.c[k]; k++)
      if (c[k] != cmp.c[k]) return c[k] < cmp.c[k];
    return c[k] < cmp.c[k];
  }
} tmp;
std::map<Type, int> Map;
int N, cnt = 2;
char A[101], B[101], cmd[101], str[101];
int getv() {
  int Cnt = 0, k = 0, cc = 0;
  while (A[k] == '&') {
    Cnt--;
    k++;
  }
  while (A[k] && A[k] != '*') str[cc++] = A[k++];
  str[cc] = 0;
  while (A[k] == '*') {
    Cnt++;
    k++;
  }
  tmp.clear();
  strcpy(tmp.c, str);
  int Tmp = Map[tmp];
  if (Tmp <= 0)
    return 0;
  else
    return Tmp + Cnt;
}
int main() {
  tmp.clear();
  strcpy(tmp.c, "void");
  Map[tmp] = 1;
  tmp.clear();
  strcpy(tmp.c, "errtype");
  Map[tmp] = -1;
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%s", cmd);
    if (cmd[4] == 'd') {
      scanf("%s", A);
      scanf("%s", B);
      int p = getv();
      tmp.clear();
      strcpy(tmp.c, B);
      if (p <= 0)
        Map[tmp] = 0;
      else
        Map[tmp] = p;
    } else {
      scanf("%s", A);
      int p = getv();
      if (p <= 0)
        puts("errtype");
      else {
        --p;
        printf("void");
        while (p--) putchar('*');
        putchar('\n');
      }
    }
  }
}
