#include <bits/stdc++.h>
using namespace std;
typedef struct _node {
  bool bVoid;
  int aster;
  int deref;
  _node() {
    bVoid = false;
    deref = aster = 0;
  }
  _node(bool b, int d, int a) {
    bVoid = b;
    deref = d;
    aster = a;
  }
} node;
int n;
map<string, node> prim;
map<string, pair<string, node> > key;
map<string, string> rkey;
int main() {
  prim["void"] = node(true, 0, 0);
  prim["errtype"] = node(false, 0, 0);
  cin >> n;
  for (int i = 0; i < n; ++i) {
    string type, f, t;
    cin >> type >> f;
    int ast = 0, deref = 0;
    bool bok = false;
    for (int j = 0; j < f.size(); ++j)
      if (f[j] == '&')
        deref++;
      else
        break;
    f.erase(0, deref);
    for (int j = f.size() - 1; j > 0; --j)
      if (f[j] == '*')
        ast++;
      else
        break;
    f.erase(f.size() - ast);
    if (prim.count(f) == 0) {
      ast = 0;
      deref = 0;
      bok = false;
    } else {
      if (prim[f].bVoid) {
        ast += prim[f].aster;
        deref += prim[f].deref;
        bok = true;
      } else {
        ast = 0;
        deref = 0;
        bok = false;
      }
    }
    if (ast < deref) bok = false;
    if (type == "typedef") {
      cin >> t;
      prim[t] = node(bok, deref, ast);
    } else {
      if (!bok)
        cout << "errtype" << endl;
      else {
        cout << "void";
        for (int k = 0; k < ast - deref; ++k) cout << "*";
        cout << endl;
      }
    }
  }
  return 0;
}
