#include <bits/stdc++.h>
using namespace std;
map<string, int> type_table = map<string, int>();
int n;
int cur_type(string param1) {
  int amp = param1.find_first_not_of('&');
  int star = param1.length() - param1.find_last_not_of('*') - 1;
  string cur_type = param1.substr(amp, param1.length() - amp - star);
  map<string, int>::iterator it = type_table.find(cur_type);
  int cur_val;
  if (it != type_table.end())
    cur_val = it->second;
  else
    cur_val = -1;
  if (cur_val < 0 || cur_val + star - amp < 0)
    return -1;
  else
    return cur_val + star - amp;
}
void tpdf(string param1, string new_name) {
  type_table[new_name] = cur_type(param1);
}
void tpof(string param1) {
  int val = cur_type(param1);
  if (val < 0)
    cout << "errtype" << endl;
  else {
    cout << "void";
    for (int i = 0; i < val; i++) cout << "*";
    cout << endl;
  }
}
int main() {
  type_table.insert(make_pair("void", 0));
  cin >> n;
  string oper, param1, param2;
  for (int i = 0; i < n; i++) {
    cin >> oper >> param1;
    if (oper == "typedef") {
      cin >> param2;
      tpdf(param1, param2);
    } else {
      tpof(param1);
    }
  }
}
