#include <bits/stdc++.h>
using namespace std;
map<string, int> mp;
string tt = "void";
int check(string s) {
  int ct1 = 0, ct2 = 0;
  int len = s.size();
  string result;
  for (int i = 0; i < len; i++) {
    if (s[i] == '&')
      ct1++;
    else if (s[i] == '*')
      ct2++;
    else
      result += s[i];
  }
  int reduce = ct2 - ct1;
  if (mp.count(result) == 0 || mp[result] < 0) {
    return -1;
  }
  reduce += mp[result];
  return reduce;
}
void out(int u) {
  cout << "void";
  for (int i = 0; i < u; i++) cout << "*";
  cout << endl;
}
int main() {
  mp[tt] = 0;
  int n;
  cin >> n;
  while (n--) {
    string str1;
    cin >> str1;
    if (str1 == "typedef") {
      string str2, str3;
      cin >> str2 >> str3;
      mp[str3] = check(str2);
    } else {
      string str2;
      cin >> str2;
      int t = check(str2);
      if (t < 0)
        cout << "errtype" << endl;
      else
        out(t);
    }
  }
  return 0;
}
