#include <bits/stdc++.h>
using namespace std;
int resolve(map<string, int> table, string source);
int main(int argc, char* argv[]) {
  string line;
  map<string, int> table;
  table.insert(pair<string, int>("void", 0));
  table.insert(pair<string, int>("errtype", -1));
  int n;
  cin >> n;
  cin.ignore();
  for (int i = 0; i < n; i++) {
    getline(cin, line);
    int first = line.find(' ');
    string operation = line.substr(0, first);
    if (operation == "typedef") {
      int second = line.find(' ', first + 1);
      string source = line.substr(first + 1, second - first - 1);
      string destination = line.substr(second + 1);
      int counter = resolve(table, source);
      if (!table.count(destination)) {
        table.insert(pair<string, int>(destination, counter));
      } else {
        table[destination] = counter;
      }
    }
    if (operation == "typeof") {
      string source = line.substr(first + 1);
      int counter = resolve(table, source);
      if (counter != -1) {
        cout << "void";
        for (int i = 0; i < counter; i++) {
          cout << "*";
        }
        cout << endl;
      } else {
        cout << "errtype" << endl;
      }
    }
  }
  return 0;
}
int resolve(map<string, int> table, string source) {
  int start = source.find_first_not_of('&');
  int stop = source.find_last_not_of('*') + 1;
  string variable = source.substr(start, stop - start);
  int address = start;
  int ref = source.size() - stop;
  int counter;
  if (table.count(variable) && (table[variable] != -1)) {
    counter = max(table[variable] + ref - address, -1);
  } else {
    counter = -1;
  }
  return counter;
}
