#include <bits/stdc++.h>
using namespace std;
map<string, int> indx;
int z[105];
int cnt;
int id(string s) {
  if (indx.find(s) != indx.end()) return indx[s];
  indx[s] = cnt++;
  return cnt - 1;
}
int doit(string A) {
  int i = 0;
  while (i < A.length() && A[i] == '&') i++;
  int j = A.length() - 1;
  while (j >= 0 && A[j] == '*') j--;
  if (indx.find(A.substr(i, j - i + 1)) == indx.end()) return -1;
  if (z[indx[A.substr(i, j - i + 1)]] < 0) return -1;
  int num = z[indx[A.substr(i, j - i + 1)]] + (A.length() - 1 - j) - i;
  return max(num, -1);
}
void print(int x) {
  if (x < 0)
    puts("errtype");
  else {
    printf("void");
    while (x--) putchar('*');
    puts("");
  }
}
int main() {
  int T;
  cnt = 0;
  id("void");
  id("errtype");
  z[1] = -1;
  char typ[50], A[50], N[50];
  scanf("%d", &T);
  while (T--) {
    scanf("%s", typ);
    if (typ[4] == 'd') {
      scanf("%s", A);
      scanf("%s", N);
      int i = id(N);
      z[i] = doit(A);
    } else {
      scanf("%s", A);
      print(doit(A));
    }
  }
  return 0;
}
