#include <bits/stdc++.h>
using namespace std;
map<string, string> mp;
string dfs(string s) {
  if (s == "void" || s == "errtype") {
    return s;
  }
  string t;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] != '*' && s[i] != '&') {
      t += s[i];
    }
  }
  int p = s.find(t);
  if (!mp.count(t)) {
    return "errtype";
  } else {
    return s.substr(0, p) + dfs(mp[t]) + s.substr(p + t.size());
  }
}
int main() {
  int n;
  scanf("%d", &n);
  string cmd;
  mp["void"] = "void";
  mp["errtype"] = "errtype";
  for (int i = 0; i < n; i++) {
    cin >> cmd;
    if (cmd == "typeof") {
      string a, b;
      cin >> a;
      string ans = dfs(a);
      int aa = count(ans.begin(), ans.end(), '&');
      int bb = count(ans.begin(), ans.end(), '*');
      if (aa > bb || ans.find("errtype") != string::npos) {
        cout << "errtype" << endl;
      } else {
        cout << ans.substr(aa, ans.size() - aa * 2) << endl;
      }
    } else {
      string a, b, c;
      cin >> a >> b;
      for (int i = 0; i < a.size(); i++) {
        if (a[i] != '*' && a[i] != '&') {
          c += a[i];
        }
      }
      if (!mp.count(c)) {
        mp[b] = "errtype";
        continue;
      }
      string ans = dfs(a);
      int aa = count(ans.begin(), ans.end(), '&');
      int bb = count(ans.begin(), ans.end(), '*');
      if (aa > bb || ans.find("errtype") != string::npos) {
        mp[b] = "errtype";
        continue;
      }
      if (c == b) {
        int p = a.find(b);
        mp[b] = a.substr(0, p) + dfs(mp[b]) + a.substr(p + b.size());
      } else {
        mp[b] = dfs(a);
      }
    }
  }
}
