#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
const long long LINF = 1000000000000000000LL;
void prepare() {}
map<string, int> good;
void print(int type) {
  if (type == -1)
    printf("errtype\n");
  else {
    printf("void");
    for (int i = 0; i < type; i++) printf("*");
    printf("\n");
  }
}
char tmp[105];
int count(string x) {
  int cc = 0;
  int i = 0;
  while (x[i] == '&') {
    cc--;
    i++;
  }
  i = x.size() - 1;
  while (x[i] == '*') {
    cc++;
    i--;
  }
  return cc;
}
string getname(string x) {
  string ret = "";
  int i = 0;
  while (x[i] == '&') i++;
  while (i < x.size() && x[i] != '*') {
    ret += x[i];
    i++;
  }
  return ret;
}
bool solve() {
  int n;
  scanf("%d", &n);
  good["void"] = 0;
  good["errtype"] = -1;
  for (int i = 0; i < n; i++) {
    scanf("%s", tmp);
    if (tmp[4] == 'd') {
      scanf("%s", tmp);
      string ff = string(tmp);
      int gg = 0;
      string nm = getname(ff);
      if (good.find(nm) == good.end())
        gg = -1;
      else {
        gg = good[nm];
        if (gg >= 0) gg += count(ff);
        if (gg < 0) gg = -1;
      }
      scanf("%s", tmp);
      good[string(tmp)] = gg;
    } else {
      scanf("%s", tmp);
      string imba = string(tmp);
      string nm = getname(imba);
      map<string, int>::iterator it = good.find(nm);
      if (it == good.end())
        printf("errtype\n");
      else {
        int gg = it->second;
        if (gg >= 0) gg += count(imba);
        if (gg < 0) gg = -1;
        print(gg);
      }
    }
  }
  return false;
}
int main() {
  prepare();
  while (solve())
    ;
  return 0;
}
