#include <bits/stdc++.h>
using namespace std;
string parse(string& what, int& ap, int& ast) {
  ap = 0;
  ast = 0;
  int i = 0, m = what.size();
  string ess = "";
  while (i < m && what[i] == '&') {
    i++;
    ap++;
  }
  while (i < m && what[i] != '*') {
    ess += what[i];
    i++;
  }
  while (i < m && what[i] == '*') {
    ast++;
    i++;
  }
  return ess;
}
int main() {
  int n;
  cin >> n;
  int ap, ast;
  map<string, int> M;
  M["void"] = 0;
  M["errtype"] = -1;
  for (int i = 0; i < n; ++i) {
    string s;
    cin >> s;
    if (s == "typeof") {
      string name;
      cin >> name;
      name = parse(name, ap, ast);
      if (!(M.find(name) != M.end()) || M[name] == -1)
        cout << "errtype";
      else {
        int v = M[name];
        v += ast - ap;
        v = max(v, -1);
        if (v == -1)
          cout << "errtype";
        else {
          cout << "void";
          for (int j = 0; j < v; ++j) cout << "*";
        }
      }
      cout << endl;
    } else {
      string what, alias;
      cin >> what >> alias;
      what = parse(what, ap, ast);
      if (!(M.find(what) != M.end()) || M[what] == -1)
        M[alias] = -1;
      else {
        int v = M[what] + ast - ap;
        v = max(v, -1);
        M[alias] = v;
      }
    }
  }
  return 0;
}
