#include <bits/stdc++.h>
using namespace std;
const int TAM = 100 + 10;
map<string, int> id;
pair<int, int> v[TAM];
pair<int, int> f(string s) {
  string s2 = "";
  int ast = 0;
  int amp = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '*')
      ast++;
    else if (s[i] == '&')
      amp++;
    else
      s2 += s[i];
  }
  int id2 = id[s2];
  if (id2 == 0) return make_pair(1, 0);
  ast -= amp;
  int tipo = v[id2].first;
  int cant = v[id2].second + ast;
  if (tipo == 1) return make_pair(1, 0);
  if (cant < 0) return make_pair(1, 0);
  return make_pair(2, cant);
}
int main() {
  int n;
  string op, r, s;
  cin >> n;
  id["errtype"] = 1;
  id["void"] = 2;
  v[1] = {1, 0};
  v[2] = {2, 0};
  int act = 3;
  for (int i = 0; i < n; i++) {
    cin >> op >> r;
    if (op == "typedef") {
      cin >> s;
      pair<int, int> x = f(r);
      if (id[s] == 0) id[s] = act++;
      v[id[s]] = x;
    } else {
      pair<int, int> x = f(r);
      if (x.first == 1)
        cout << "errtype";
      else
        cout << "void";
      for (int j = 0; j < x.second; j++) cout << "*";
      cout << endl;
    }
  }
  return 0;
}
