#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  map<string, int> table;
  table.insert(pair<string, int>("void", 0));
  while (n--) {
    string cmd;
    cin >> cmd;
    if (cmd == "typedef") {
      string from, to, raw;
      cin >> from >> to;
      int depth = 0, i = 0, j = from.size() - 1;
      for (; i < j; ++i) {
        if (from[i] != '&') {
          break;
        }
        --depth;
      }
      for (; i < j; --j) {
        if (from[j] != '*') {
          break;
        }
        ++depth;
      }
      raw = from.substr(i, j - i + 1);
      map<string, int>::iterator it = table.find(raw);
      if (it == table.end()) {
        table[to] = -1;
      } else if (it->second < 0 || it->second + depth < 0) {
        table[to] = -1;
      } else {
        table[to] = it->second + depth;
      }
    } else if (cmd == "typeof") {
      string type, raw;
      cin >> type;
      int depth = 0, i = 0, j = type.size() - 1;
      for (; i < j; ++i) {
        if (type[i] != '&') {
          break;
        }
        --depth;
      }
      for (; i < j; --j) {
        if (type[j] != '*') {
          break;
        }
        ++depth;
      }
      raw = type.substr(i, j - i + 1);
      map<string, int>::iterator it = table.find(raw);
      if (it == table.end()) {
        cout << "errtype" << endl;
      } else if (it->second < 0 || it->second + depth < 0) {
        cout << "errtype" << endl;
      } else {
        cout << "void" << string(it->second + depth, '*') << endl;
      }
    }
  }
  return 0;
}
