#include <bits/stdc++.h>
using namespace std;
const int inf = 2000 * 1000;
const long long linf = 2000000000000000000LL;
const double eps = 1e-9;
void prepare() {}
int n;
map<string, int> q;
string s, t, com, m;
int c;
void parse(string &s, string &t, int &c) {
  c = 0;
  t = "";
  int pos = 0;
  while (pos < (int)s.size() && s[pos] == '&') {
    c--;
    pos++;
  }
  while (pos < (int)s.size() && s[pos] != '*') {
    t.push_back(s[pos]);
    pos++;
  }
  while (pos < (int)s.size() && s[pos] == '*') {
    c++;
    pos++;
  }
  assert(pos == (int)s.size());
}
bool solve() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> com;
    if (com == "typedef") {
      cin >> s >> m;
      parse(s, t, c);
      if (t == "errtype" || q.find(t) == q.end() && t != "void") {
        if (q.find(m) != q.end()) q.erase(q.find(m));
        q.insert(make_pair(m, -inf));
      } else {
        if (t != "void") c += q.find(t)->second;
        if (q.find(m) != q.end()) q.erase(q.find(m));
        if (c < 0)
          q.insert(make_pair(m, -inf));
        else
          q.insert(make_pair(m, c));
      }
    } else if (com == "typeof") {
      cin >> s;
      parse(s, t, c);
      if (t == "errtype" || q.find(t) == q.end() && t != "void")
        printf("errtype\n");
      else {
        if (t != "void") c += q.find(t)->second;
        if (c < 0)
          printf("errtype\n");
        else {
          printf("void");
          for (int it = 0; it < c; it++) printf("*");
          printf("\n");
        }
      }
    } else
      assert(false);
  }
  return false;
}
int main() {
  prepare();
  while (solve())
    ;
  return 0;
}
