#include <bits/stdc++.h>
using namespace std;
int t;
map<string, int> name;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  name["void"] = 0;
  name["errtype"] = -1;
  while (t--) {
    string op;
    cin >> op;
    if (op == "typedef") {
      string a, b;
      cin >> a >> b;
      int n = a.size();
      int asterisk = n - 1;
      while (a[asterisk] == '*') asterisk--;
      int ampersand = 0;
      while (a[ampersand] == '&') ampersand++;
      a = a.substr(ampersand, asterisk - ampersand + 1);
      asterisk = n - 1 - asterisk;
      int cur = 0;
      if (name.count(a)) {
        cur = name[a];
      } else {
        cur = -1;
      }
      if (cur != -1) {
        cur += asterisk - ampersand;
        if (cur < 0) cur = -1;
      }
      name[b] = cur;
    } else {
      string a;
      cin >> a;
      int n = a.size();
      int asterisk = n - 1;
      while (a[asterisk] == '*') asterisk--;
      int ampersand = 0;
      while (a[ampersand] == '&') ampersand++;
      a = a.substr(ampersand, asterisk - ampersand + 1);
      asterisk = n - 1 - asterisk;
      if (!name.count(a) || name[a] == -1) {
        cout << "errtype\n";
      } else {
        int cur = name[a] + asterisk - ampersand;
        if (cur < 0)
          cout << "errtype\n";
        else
          cout << "void" << string(cur, '*') << "\n";
      }
    }
  }
  return 0;
}
