#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout << setprecision(32);
  int n;
  cin >> n;
  map<string, int> mp;
  mp["void"] = 0;
  mp["errtype"] = -1;
  for (int i = 0; i < n; i++) {
    string a, b, c;
    cin >> a >> b;
    if (a == "typedef") {
      cin >> c;
      int cnt = 0;
      while (!b.empty() && b.back() == '*') {
        cnt++;
        b.pop_back();
      }
      while (!b.empty() && b[0] == '&') {
        cnt--;
        b = b.substr(1);
      }
      if (!mp.count(b)) mp[b] = -1;
      if (mp[b] == -1)
        mp[c] = -1;
      else if (cnt + mp[b] < 0)
        mp[c] = -1;
      else
        mp[c] = cnt + mp[b];
    } else {
      int cnt = 0;
      while (!b.empty() && b.back() == '*') {
        cnt++;
        b.pop_back();
      }
      while (!b.empty() && b[0] == '&') {
        cnt--;
        b = b.substr(1);
      }
      if (!mp.count(b)) {
        cout << "errtype\n";
      } else if (mp[b] < 0 || cnt + mp[b] < 0) {
        cout << "errtype\n";
      } else {
        cout << "void";
        int k = cnt + mp[b];
        while (k--) cout << '*';
        cout << '\n';
      }
    }
  }
  return 0;
}
