#include <bits/stdc++.h>
using namespace std;
map<string, int> M;
int main(int argc, char* argv[]) {
  char c[256];
  string s, t, t1, t2;
  int i, n, k, r, j;
  cin >> n;
  M["void"] = 0;
  for (i = 0; i < n; i++) {
    cin >> s;
    if (s == "typedef") {
      cin >> t1 >> t2;
      r = 0;
      for (j = 0; t1[j] == '&'; j++, r--) {
      }
      for (k = t1.size() - 1; k >= 0 && t1[k] == '*'; k--, r++) {
      }
      t1 = t1.substr(j, k - j + 1);
      if (t1 == "void") {
        if (r >= 0)
          M[t2] = r;
        else
          M.erase(t2);
      } else {
        if (M.find(t1) == M.end()) {
          M.erase(t2);
        } else if (M[t1] + r >= 0)
          M[t2] = M[t1] + r;
        else
          M.erase(t2);
      }
    } else {
      cin >> t;
      r = 0;
      for (j = 0; t[j] == '&'; j++, r--) {
      }
      for (k = t.size() - 1; k >= 0 && t[k] == '*'; k--, r++) {
      }
      t = t.substr(j, k - j + 1);
      if (M.find(t) == M.end())
        cout << "errtype" << endl;
      else {
        k = M[t] + r;
        if (k < 0)
          cout << "errtype" << endl;
        else {
          cout << "void";
          for (; k > 0; k--) cout << "*";
          cout << endl;
        }
      }
    }
  }
  return 0;
}
