#include <bits/stdc++.h>
using namespace std;
map<string, int> mp;
int getval(string a) {
  string bare;
  int cnt = 0;
  for (register int j = (0); j < (int)((int)(a).size()); ++j) {
    if (a[j] == '*')
      cnt++;
    else if (a[j] == '&')
      cnt--;
    else
      bare += a[j];
  }
  if (mp.count(bare) == 0) return -10000;
  cnt += mp[bare];
  return cnt < 0 ? -10000 : cnt;
}
int main() {
  mp["void"] = 0;
  int n;
  cin >> n;
  for (register int i = (0); i < (int)n; ++i) {
    string com;
    cin >> com;
    if (com == "typedef") {
      string a, b;
      cin >> a >> b;
      mp[b] = getval(a);
    } else if (com == "typeof") {
      string a;
      cin >> a;
      int cnt = getval(a);
      if (cnt < 0)
        cout << "errtype" << endl;
      else
        cout << "void" << string(cnt, '*') << endl;
    }
  }
  return 0;
}
