#include <bits/stdc++.h>
bool comp(int i, int j) { return i > j; }
using namespace std;
struct dtp {
  string type;
  int amp, str;
};
int main() {
  map<string, dtp> mp;
  int n;
  dtp tp;
  dtp err;
  err.type = "errtype";
  err.str = err.amp = 0;
  dtp vd;
  vd.type = "void";
  vd.str = vd.amp = 0;
  scanf("%d", &n);
  int i, c, sz;
  int ap, sr, sb;
  string s, a, b, sdt, st;
  mp["void"] = vd;
  mp["errtype"] = err;
  for (c = 0; c < n; c++) {
    cin >> s;
    if (s == "typedef") {
      cin >> a >> b;
      ap = sr = 0;
      sz = a.size();
      i = 0;
      st = "";
      while (a[i] == '&') {
        ap++;
        i++;
      }
      while (i < sz && a[i] != '*') {
        st.append(1, a[i]);
        i++;
      }
      sr = sz - i;
      sdt = mp[st].type;
      if (sdt == "") {
        mp[b] = err;
        continue;
      }
      if (sdt == "void") {
        sr += mp[st].str;
        ap += mp[st].amp;
        sb = min(sr, ap);
        sr -= sb;
        ap -= sb;
        if (ap > 0) {
          tp = err;
        } else {
          tp.type = "void";
          tp.str = sr;
          tp.amp = ap;
        }
        mp[b] = tp;
      } else
        mp[b] = err;
    } else {
      cin >> a;
      sz = a.size();
      i = 0;
      ap = sr = 0;
      st = "";
      while (a[i] == '&') {
        ap++;
        i++;
      }
      while (i < sz && a[i] != '*') {
        st.append(1, a[i]);
        i++;
      }
      sr = sz - i;
      sdt = mp[st].type;
      ap += mp[st].amp;
      sr += mp[st].str;
      sb = min(ap, sr);
      ap -= sb;
      sr -= sb;
      if (ap > 0 || sdt == "errtype" || sdt == "")
        cout << "errtype" << endl;
      else {
        sdt.append(sr, '*');
        cout << sdt << endl;
      }
    }
  }
  return 0;
}
