#include <bits/stdc++.h>
using namespace std;
struct tt {
  bool er;
  int zv;
  void out() {
    if (er)
      printf("errtype\n");
    else {
      printf("void");
      for (int i(0); i <= (zv - 1); i++) {
        printf("*");
      }
      printf("\n");
    }
  }
};
int main() {
  map<string, tt> cur;
  int n;
  scanf("%d", &n);
  string temp;
  getline(cin, temp);
  for (int i(0); i <= (n - 1); i++) {
    getline(cin, temp);
    string tp = temp.substr(0, temp.find(" "));
    temp.erase(temp.begin(), temp.begin() + temp.find(" ") + 1);
    if (tp == "typeof") {
      string what = temp;
      int zvdif = 0;
      while (what[0] == '&') zvdif--, what.erase(0, 1);
      while (what[what.length() - 1] == '*')
        zvdif++, what.erase(what.length() - 1, 1);
      if (what == "void") {
        printf("void\n");
      } else {
        if (cur.count(what) == 0) {
          printf("errtype\n");
        } else {
          tt n = cur[what];
          n.zv += zvdif;
          if (n.zv < 0) n.er = true;
          n.out();
        }
      }
    } else {
      string what = temp.substr(0, temp.find(" "));
      temp.erase(temp.begin(), temp.begin() + temp.find(" ") + 1);
      string towhat = temp;
      int zvdif = 0;
      while (what[0] == '&') zvdif--, what.erase(0, 1);
      while (what[what.length() - 1] == '*')
        zvdif++, what.erase(what.length() - 1, 1);
      if (what == "void") {
        tt n;
        if (zvdif < 0)
          n.er = true;
        else
          n.zv = zvdif, n.er = false;
        cur[towhat] = n;
      } else if (what == "errtype") {
        tt n;
        n.er = true;
        cur[towhat] = n;
      } else {
        if (cur.count(what) == 0) {
          tt n;
          n.er = true;
          cur[towhat] = n;
        } else {
          tt n = cur[what];
          n.zv += zvdif;
          if (n.zv < 0) n.er = true;
          cur[towhat] = n;
        }
      }
    }
  }
  return 0;
}
