#include <bits/stdc++.h>
using namespace std;
set<string> st;
int getval(string s, map<string, int>& mp) {
  int val = 0, sz = s.size();
  string cur;
  for (int i = 0; i < sz; i++) {
    char ch = s[i];
    if (ch == '&')
      val--;
    else if (ch == '*')
      val++;
    else
      cur += ch;
  }
  if (st.find(cur) == st.end()) return -1;
  int ans = mp[cur];
  if (ans < 0) return -1;
  ans += val;
  if (ans < 0) return -1;
  return ans;
}
void print(int n) {
  if (n < 0)
    cout << "errtype" << endl;
  else {
    cout << "void";
    for (int i = 0; i < n; i++) cout << '*';
    cout << endl;
  }
}
int main() {
  int n;
  cin >> n;
  map<string, int> mp;
  mp["void"] = 0;
  st.insert("void");
  while (n--) {
    string cmd, a, b;
    cin >> cmd >> a;
    int cur = getval(a, mp);
    if (cmd == "typedef") {
      cin >> b;
      mp[b] = cur;
      st.insert(b);
    } else
      print(cur);
  }
  return 0;
}
