#include <bits/stdc++.h>
using namespace std;
struct Type {
  bool error;
  int pcnt;
  Type(bool _error = true, int _pcnt = -1) : error(_error), pcnt(_pcnt) {}
};
map<string, Type> types;
Type getType(const char *str) {
  int del = 0, add = 0;
  string name = "";
  for (int i = 0; str[i]; i++)
    if (str[i] == '&')
      del++;
    else if (str[i] == '*')
      add++;
    else
      name += str[i];
  if (!types.count(name)) return Type(true);
  Type cur = types[name];
  if (cur.error) return Type(true);
  assert(cur.pcnt >= 0);
  for (int i = 0; i < add; i++)
    if (++cur.pcnt < 0) return Type(true);
  for (int i = 0; i < del; i++)
    if (--cur.pcnt < 0) return Type(true);
  return cur;
}
char op[1024];
char n1[1024];
char n2[1024];
int main() {
  int n;
  while (scanf("%d", &n) >= 1) {
    types.clear();
    types.insert(make_pair("void", Type(false, 0)));
    types.insert(make_pair("errtype", Type(true)));
    for (int i = 0; i < n; i++) {
      scanf(" %s %s", op, n1);
      Type first = getType(n1);
      if (!strcmp(op, "typedef")) {
        scanf(" %s", n2);
        types.erase(n2);
        types.insert(make_pair(n2, first));
      } else if (!strcmp(op, "typeof")) {
        if (first.error)
          printf("errtype");
        else {
          printf("void");
          for (int i = 0; i < first.pcnt; i++) printf("*");
        }
        printf("\n");
      } else
        assert(false);
    }
    break;
  }
  return 0;
}
