#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-12;
const int INF = 999999999;
char buf[1000];
map<string, int> f;
int Com(string s) {
  int res = 0;
  while (s[int((s).size()) - 1] == '*') {
    ++res;
    s = s.substr(0, int((s).size()) - 1);
  }
  while (s[0] == '&') {
    --res;
    s = s.substr(1);
  }
  map<string, int>::iterator i = f.find(s);
  if (i == f.end()) return -1;
  if (i->second == -1) return -1;
  res += i->second;
  if (res < 0) res = -1;
  return res;
}
void Output(int x) {
  if (x < 0) {
    printf("errtype\n");
    return;
  }
  printf("void");
  for (int i = 0; i < x; ++i) printf("*");
  printf("\n");
}
int main() {
  int n;
  string s, a, b;
  f.clear();
  f["void"] = 0;
  f["errtype"] = -1;
  scanf("%d", &n);
  while (n--) {
    scanf("%s", buf);
    s = buf;
    if (s == "typedef") {
      scanf("%s", buf);
      a = buf;
      int x = Com(a);
      scanf("%s", buf);
      b = buf;
      f[b] = x;
    } else {
      scanf("%s", buf);
      a = buf;
      int x = Com(a);
      Output(x);
    }
  }
  return 0;
}
