#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  while (cin >> N) {
    map<string, int> var;
    var["void"] = 0;
    for (int itr = 0; itr < (int)(N); ++itr) {
      string query, type;
      cin >> query >> type;
      int cnt = 0;
      while (type[(int)((type).size()) - 1] == '*')
        type = type.substr(0, (int)((type).size()) - 1), cnt++;
      while (type[0] == '&') type = type.substr(1), cnt--;
      if (!((var).find(type) != (var).end())) {
        cnt = -666666;
      } else
        cnt += var[type];
      if (cnt < 0) cnt = -666666;
      if (query == "typedef") {
        string name;
        cin >> name;
        var[name] = cnt;
      } else {
        if (cnt < 0)
          puts("errtype");
        else {
          printf("void");
          for (int i = 0; i < (int)(cnt); ++i) printf("*");
          puts("");
        }
      }
    }
  }
}
