#include <bits/stdc++.h>
using namespace std;
map<string, int> mp;
int main() {
  mp["void"] = 1;
  int n;
  cin >> n;
  getchar();
  while (n--) {
    string ss;
    cin >> ss;
    if (ss == "typedef") {
      string s1, s2;
      cin >> s1 >> s2;
      int type = 0;
      string str1 = "";
      for (int i = 0; i < s1.length(); i++) {
        if (s1[i] == '*')
          type++;
        else if (s1[i] == '&')
          type--;
        else
          str1 += s1[i];
      }
      int cnt = mp[str1];
      if (cnt > 0)
        cnt += type;
      else
        cnt = 0;
      mp[s2] = cnt;
    } else {
      string s1;
      cin >> s1;
      int type = 0;
      string str1 = "";
      for (int i = 0; i < s1.length(); i++) {
        if (s1[i] == '*')
          type++;
        else if (s1[i] == '&')
          type--;
        else
          str1 += s1[i];
      }
      int cnt = mp[str1];
      if (cnt > 0)
        cnt += type;
      else
        cnt = 0;
      if (cnt <= 0)
        puts("errtype");
      else {
        printf("void");
        for (int i = 1; i < cnt; i++) printf("*");
        puts("");
      }
    }
  }
  return 0;
}
