#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:134217728")
using namespace std;
template <class T>
T abs(T x) {
  return x > 0 ? x : -x;
}
int n;
map<string, int> m;
int main() {
  cin >> n;
  m["void"] = 0;
  for (int i = 0; i < (n); i++) {
    string o;
    cin >> o;
    if (o == "typedef") {
      string s1, s2;
      cin >> s1 >> s2;
      int c1 = 0, c2 = 0;
      while (s1[0] == '&') {
        c1++;
        s1.erase(0, 1);
      }
      while (s1[((int)(s1).size()) - 1] == '*') {
        c2++;
        s1.erase(((int)(s1).size()) - 1, 1);
      }
      if (m.count(s1)) {
        int x = m[s1] + c2 - c1;
        if (x >= 0)
          m[s2] = x;
        else
          m.erase(s2);
      } else
        m.erase(s2);
    } else {
      string s1;
      cin >> s1;
      int c1 = 0, c2 = 0;
      while (s1[0] == '&') {
        c1++;
        s1.erase(0, 1);
      }
      while (s1[((int)(s1).size()) - 1] == '*') {
        c2++;
        s1.erase(((int)(s1).size()) - 1, 1);
      }
      if (m.count(s1)) {
        int x = m[s1] + c2 - c1;
        if (x >= 0) {
          cout << "void";
          for (int j = 0; j < (x); j++) cout << "*";
          cout << endl;
        } else
          cout << "errtype" << endl;
      } else
        cout << "errtype" << endl;
    }
  }
  return 0;
}
