#include <bits/stdc++.h>
using namespace std;
const int N = 10005;
string fun(string tmp, int &cnt1, int &cnt2) {
  string res;
  for (int i = 0; i < (int)tmp.length(); i++) {
    if (tmp[i] == '&')
      cnt1++;
    else if (tmp[i] == '*')
      cnt2++;
    else
      res += tmp[i];
  }
  return res;
}
int main() {
  int n;
  cin >> n;
  map<string, string> hash;
  hash.insert(make_pair("void", "void"));
  hash.insert(make_pair("errtype", "errtype"));
  for (int j = 0; j < n; j++) {
    string substr[3];
    cin >> substr[0];
    if (substr[0] == "typedef") {
      cin >> substr[1] >> substr[2];
      int cnt1 = 0, cnt2 = 0;
      string tmp = fun(substr[1], cnt1, cnt2);
      if (hash.find(tmp) == hash.end()) {
        if (tmp == "void" && cnt1 <= cnt2) {
          for (int i = 0; i < cnt2 - cnt1; i++) tmp += '*';
          if (hash.find(substr[2]) != hash.end()) hash.erase(substr[2]);
          hash.insert(make_pair(substr[2], tmp));
        } else {
          if (hash.find(substr[2]) != hash.end()) hash.erase(substr[2]);
          hash.insert(make_pair(substr[2], "errtype"));
        }
      } else {
        int ccnt1 = 0, ccnt2 = 0;
        string bre = fun(hash[tmp], ccnt1, ccnt2);
        if (bre == "errtype") {
          if (hash.find(substr[2]) != hash.end()) hash.erase(substr[2]);
          hash.insert(make_pair(substr[2], "errtype"));
        } else if (ccnt1 + cnt1 <= ccnt2 + cnt2) {
          for (int i = 0; i < ccnt2 + cnt2 - ccnt1 - cnt1; i++) bre += '*';
          if (hash.find(substr[2]) != hash.end()) hash.erase(substr[2]);
          hash.insert(make_pair(substr[2], bre));
        } else {
          if (hash.find(substr[2]) != hash.end()) hash.erase(substr[2]);
          hash.insert(make_pair(substr[2], "errtype"));
        }
      }
    } else {
      int cnt1 = 0, cnt2 = 0;
      cin >> substr[1];
      string tmp = fun(substr[1], cnt1, cnt2);
      if (hash.find(tmp) == hash.end())
        puts("errtype");
      else {
        int ccnt1 = 0, ccnt2 = 0;
        string pre = fun(hash[tmp], ccnt1, ccnt2);
        if (pre == "errtype")
          cout << "errtype" << endl;
        else if (ccnt1 + cnt1 <= ccnt2 + cnt2) {
          cout << pre;
          for (int i = 0; i < (cnt2 + ccnt2) - (cnt1 + ccnt1); i++) cout << '*';
          cout << endl;
        } else
          puts("errtype");
      }
    }
  }
  return 0;
}
