#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse4")
#pragma GCC optimize("unroll-loops")
using namespace std;
map<string, int> mp;
int get(string s) {
  int l = count((s).begin(), (s).end(), '&'),
      r = count((s).begin(), (s).end(), '*');
  s = s.substr(l, (int)s.size() - l - r);
  if (!mp.count(s)) return -1;
  if (mp[s] < 0 or mp[s] + r < l) return -1;
  return mp[s] + r - l;
}
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, x;
  string s, a, b;
  mp["void"] = 0;
  cin >> n;
  while (n--) {
    cin >> s;
    if (s == "typedef") {
      cin >> a >> b;
      mp[b] = get(a);
    } else {
      cin >> a;
      x = get(a);
      if (x < 0)
        cout << "errtype";
      else {
        cout << "void";
        while (x--) cout << "*";
      }
      cout << '\n';
    }
  }
  return 0;
}
