#include <bits/stdc++.h>
using namespace std;
int main() {
  map<string, int> m;
  m["void"] = 0;
  m["errtype"] = -1;
  int n;
  scanf("%d", &n);
  while (n--) {
    string t;
    cin >> t;
    if (t == "typedef") {
      string a, b;
      cin >> a >> b;
      int len = a.length(), i = 0, val = 0;
      string temp;
      while (i < len && a[i] == '&') {
        i++;
        val--;
      }
      while (i < len & a[i] != '*') {
        temp += a[i];
        i++;
      }
      if (m.count(temp) == 0 || m[temp] < 0) {
        m[b] = -1;
        continue;
      }
      while (i < len) {
        val++;
        i++;
      }
      if (m[temp] + val < 0) {
        m[b] = -1;
        continue;
      }
      m[b] = val + m[temp];
    } else {
      string b;
      cin >> b;
      int len = b.length(), i = 0, val = 0;
      string temp;
      while (i < len && b[i] == '&') {
        i++;
        val--;
      }
      while (i < len && b[i] != '*') {
        temp += b[i];
        i++;
      }
      if (m.count(temp) == 0 || m[temp] < 0) {
        printf("errtype\n");
        continue;
      }
      while (i < len) {
        i++;
        val++;
      }
      if (m[temp] + val < 0) {
        printf("errtype\n");
        continue;
      }
      printf("void");
      val = val + m[temp];
      for (int i = int(0); i <= int(val - 1); i++) printf("*");
      printf("\n");
    }
  }
  return 0;
}
