#include <bits/stdc++.h>
using namespace std;
int n, m;
int k;
bool debug = false;
struct uz {
  int w = 0, l = 0, r = 0;
  uz() {}
  uz(int l, int r) : l(l), r(r) {}
  void dd() {
    if (w) return;
    if (l < 0 || r < 0) {
      w = 1;
      return;
    }
    int mm = min(l, r);
    l -= mm;
    r -= mm;
    if (l != 0) w = 1;
  }
  void pp() {
    if (w) {
      puts("errtype");
      return;
    }
    string t = "void";
    for (int i = 0; i < r; i++) t += '*';
    puts(t.c_str());
  }
};
map<string, uz> pp;
int main() {
  scanf("%d", &n);
  string a, b, c;
  pp["void"] = uz(0, 0);
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    string tmp = "";
    int l = 0, r = 0;
    for (int j = 0; j < b.size(); j++) {
      if (b[j] == '&')
        l++;
      else if (b[j] == '*')
        r++;
      else
        tmp += b[j];
    }
    if (a == "typedef") {
      cin >> c;
      if (tmp == "void") {
        uz u = uz(l, r);
        u.dd();
        pp[c] = u;
      } else {
        if (pp.find(tmp) == pp.end()) {
          pp.erase(c);
          continue;
        }
        uz u = uz(pp[tmp].l + l, pp[tmp].r + r);
        u.w = pp[tmp].w;
        u.dd();
        pp[c] = u;
      }
    } else {
      if (pp.find(tmp) == pp.end()) {
        puts("errtype");
        continue;
      }
      uz u = uz(pp[tmp].l + l, pp[tmp].r + r);
      u.w = pp[tmp].w;
      u.dd();
      u.pp();
    }
  }
  return 0;
}
