#include <bits/stdc++.h>
using namespace std;
map<string, string> mp;
string com, type, name;
void f(string a) {
  if (a == "def")
    cin >> type >> name;
  else
    cin >> type;
  int pt = 0, de = 0, l = type.length();
  char line[1000];
  memset(line, 0, sizeof(line));
  sscanf(type.c_str(), "%[&]s", line);
  de += strlen(line);
  memset(line, 0, sizeof(line));
  sscanf(type.c_str(), "%[^*]s", line);
  pt += l - strlen(line);
  string ntype = "";
  for (int i = de; i < l - pt; i++) ntype += type[i];
  if (ntype == "void") {
    if (pt - de < 0) {
      if (a == "def")
        mp[name] = "errtype";
      else
        printf("errtype\n");
    } else {
      string nntype = "void";
      for (int i = 0; i < pt - de; i++) nntype += '*';
      if (a == "def")
        mp[name] = nntype;
      else
        cout << nntype << endl;
    }
  } else if (ntype == "errtype" || mp.find(ntype) == mp.end() ||
             mp[ntype] == "errtype")
    if (a == "def")
      mp[name] = "errtype";
    else
      printf("errtype\n");
  else {
    memset(line, 0, sizeof(line));
    l = mp[ntype].length();
    sscanf(mp[ntype].c_str(), "%[&]s", line);
    de += strlen(line);
    memset(line, 0, sizeof(line));
    sscanf(mp[ntype].c_str(), "%[^*]s", line);
    pt += l - strlen(line);
    if (pt - de < 0)
      if (a == "def")
        mp[name] = "errtype";
      else
        printf("errtype\n");
    else {
      string nntype = "void";
      for (int i = 0; i < pt - de; i++) nntype += '*';
      if (a == "def")
        mp[name] = nntype;
      else
        cout << nntype << endl;
    }
  }
}
int main() {
  int n;
  scanf("%d", &n);
  while (n--) {
    cin >> com;
    if (com == "typedef")
      f("def");
    else if (com == "typeof")
      f("of");
  }
  return 0;
}
