#include <bits/stdc++.h>
using namespace std;
map<string, string> table;
int n;
string get_type(string var) {
  int pre = 0, suf = 0;
  while (var[0] == '&') ++pre, var.erase(0, 1);
  while (var[var.size() - 1] == '*') ++suf, var.erase(var.size() - 1, 1);
  if (table.count(var) == 0)
    return "errtype";
  else
    var = table[var];
  if (var == "errtype") return var;
  while (var[0] == '&') ++pre, var.erase(0, 1);
  while (var[var.size() - 1] == '*') ++suf, var.erase(var.size() - 1, 1);
  suf -= pre;
  if (suf < 0) return "errtype";
  for (int i = 0; i < suf; ++i) var += '*';
  return var;
}
void solve() {
  table.clear();
  table[string("void")] = "void";
  string op, var, var_n;
  for (int l = 0; l < n; ++l) {
    cin >> op;
    if (op == "typedef") {
      cin >> var >> var_n;
      table[var_n] = get_type(var);
    } else {
      cin >> var;
      cout << get_type(var) << endl;
    }
  }
}
int main() {
  cin >> n;
  solve();
  return 0;
}
