#include <bits/stdc++.h>
using namespace std;
map<string, int> ma;
int n, m;
string s1, s2, s3;
int main() {
  cin >> n;
  ma.clear();
  ma["void"] = 0;
  ma["errtype"] = -1;
  for (int i = 0; i < n; i++) {
    cin >> s1 >> s2;
    if (s1 == "typedef") {
      cin >> s3;
      string ans = "";
      int n1 = 0, n2 = 0;
      for (int j = 0, len = s2.length(); j < len; j++)
        if (s2[j] == '&')
          n1++;
        else if (s2[j] == '*')
          n2++;
        else
          ans += s2[j];
      n2 -= n1;
      int tmp;
      if (ma.find(ans) != ma.end())
        tmp = ma[ans];
      else
        tmp = -1;
      if (tmp < 0)
        n2 = -1;
      else
        n2 += tmp;
      if (n2 < 0)
        ma[s3] = -1;
      else
        ma[s3] = n2;
    } else {
      string ans = "";
      int n1 = 0, n2 = 0;
      for (int j = 0, len = s2.length(); j < len; j++)
        if (s2[j] == '&')
          n1++;
        else if (s2[j] == '*')
          n2++;
        else
          ans += s2[j];
      n2 -= n1;
      int tmp;
      if (ma.find(ans) != ma.end())
        tmp = ma[ans];
      else
        tmp = -1;
      if (tmp < 0)
        n2 = -1;
      else
        n2 += tmp;
      if (n2 < 0)
        printf("errtype\n");
      else {
        printf("void");
        for (int i = 0; i < n2; i++) printf("*");
        printf("\n");
      }
    }
  }
  return 0;
}
