#include <bits/stdc++.h>
using namespace std;
map<string, int> m;
int n;
pair<char*, int> count(char* name) {
  int ast = 0, amp = 0, it = 0;
  char* pt;
  while (name[it] == '&') it++, amp++;
  int firstlet = it;
  while (name[it] != '*' && name[it] != '\0') it++;
  int firstast = it;
  while (name[it] == '*') it++, ast++;
  name[firstast] = '\0';
  pt = &name[firstlet];
  return make_pair(pt, ast - amp);
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    char comm[256], name[256], type[256];
    scanf(" %s %s", comm, name);
    ;
    if (!strcmp(comm, "typeof")) {
      pair<char*, int> pTmp = count(name);
      char* pt = pTmp.first;
      int op = pTmp.second;
      if (strcmp(pt, "void") && m.find(pt) == m.end())
        printf("errtype\n");
      else {
        if (m[pt] < 0 || (m[pt] + op) < 0)
          printf("errtype\n");
        else {
          op += m[pt];
          printf("void");
          for (int i = 0; i < op; i++) printf("*");
          printf("\n");
        }
      }
    } else {
      scanf(" %s", type);
      ;
      pair<char*, int> pTmp = count(name);
      char* pt = pTmp.first;
      int op = pTmp.second;
      if (!strcmp(pt, "void"))
        m[type] = op;
      else if (!strcmp(pt, "errtype"))
        m[type] = -1;
      else {
        if (m.find(pt) != m.end()) {
          int prev = m[pt];
          ;
          if (prev < 0)
            m[type] = -1;
          else
            m[type] = prev + op;
        } else
          m[type] = -1;
      }
    };
  }
  return 0;
}
