#include <bits/stdc++.h>
using namespace std;
map<string, int> typ;
int N;
int main() {
  typ["void"] = 0;
  cin >> N;
  while (N--) {
    string com;
    cin >> com;
    if (com == "typeof") {
      string t;
      cin >> t;
      int amp = 0, star = 0;
      while (t[0] == '&') {
        amp++;
        t = t.substr(1);
      }
      while (t[t.size() - 1] == '*') {
        star++;
        t = t.substr(0, t.size() - 1);
      }
      if (!typ.count(t) || typ[t] < 0 || typ[t] + star - amp < 0)
        cout << "errtype" << endl;
      else {
        cout << "void";
        for (int i = 0; i < (int)typ[t] + star - amp; i++) cout << "*";
        cout << endl;
      }
    } else {
      string t, s;
      cin >> t >> s;
      int amp = 0, star = 0;
      while (t[0] == '&') {
        amp++;
        t = t.substr(1);
      }
      while (t[t.size() - 1] == '*') {
        star++;
        t = t.substr(0, t.size() - 1);
      }
      if (!typ.count(t))
        typ[s] = -1;
      else if (typ[t] < 0 || typ[t] + star - amp < 0)
        typ[s] = -1;
      else
        typ[s] = typ[t] + star - amp;
    }
  }
}
