#include <bits/stdc++.h>
using namespace std;
map<string, int> mp;
int main() {
  string com;
  int n;
  while (cin >> n) {
    mp.clear();
    mp["void"] = 0;
    while (n--) {
      cin >> com;
      if (com == "typedef") {
        string s1, s2;
        cin >> s1 >> s2;
        int cnt(0);
        int l(0), r((int)s1.size() - 1);
        while (s1[l] == '&') cnt--, ++l;
        while (s1[r] == '*') cnt++, --r;
        s1 = s1.substr(l, r - l + 1);
        if (s1 == "void") {
          if (cnt >= 0)
            mp[s2] = cnt;
          else if (mp.find(s2) != mp.end())
            mp.erase(s2);
        } else {
          if (mp.find(s1) != mp.end() && cnt + mp[s1] >= 0)
            mp[s2] = cnt + mp[s1];
          else if (mp.find(s2) != mp.end())
            mp.erase(s2);
        }
      } else {
        string s1;
        cin >> s1;
        int cnt(0);
        int l(0), r((int)s1.size() - 1);
        while (s1[l] == '&') cnt--, ++l;
        while (s1[r] == '*') cnt++, --r;
        s1 = s1.substr(l, r - l + 1);
        if (mp.find(s1) == mp.end() || cnt + mp[s1] < 0)
          cout << "errtype\n";
        else {
          cout << "void";
          cnt += mp[s1];
          for (int i(0); i < cnt; ++i) cout << "*";
          cout << endl;
        }
      }
    }
  }
  return 0;
}
