#include <bits/stdc++.h>
using namespace std;
string s, t;
map<string, int> m;
int main() {
  m["void"] = 0;
  int n;
  cin >> n;
  for (int q = 0; q < (int)(n); q++) {
    cin >> s;
    if (s.size() == 7) {
      cin >> s;
      int i = 0;
      for (; s[i] == '&'; i++)
        ;
      int j = i;
      for (; j < (int)(s.size()) && s[j] != '*'; j++)
        ;
      t = s.substr(i, j - i);
      i = s.size() - j - i;
      cin >> s;
      if (m.find(t) == m.end() || m[t] == -1 || m[t] + i < 0) {
        m[s] = -1;
      } else {
        m[s] = m[t] + i;
      }
    } else {
      cin >> s;
      int i = 0;
      for (; s[i] == '&'; i++)
        ;
      int j = i;
      for (; j < (int)(s.size()) && s[j] != '*'; j++)
        ;
      t = s.substr(i, j - i);
      i = s.size() - j - i;
      if (m.find(t) == m.end() || m[t] == -1 || m[t] + i < 0) {
        cout << "errtype";
      } else {
        cout << "void";
        for (int j = 0; j < (int)(m[t] + i); j++) {
          cout << '*';
        }
      }
      cout << endl;
    }
  }
}
