#include <bits/stdc++.h>
using namespace std;
map<string, string> p;
string err = "errtype";
string op(string s1) {
  int k1 = 0;
  int k2 = 0;
  while (s1[0] == '&') {
    k1++;
    s1.erase(0, 1);
  }
  while (s1[s1.size() - 1] == '*') {
    k2++;
    s1.erase(s1.size() - 1, 1);
  }
  string sn = s1;
  sn = p[sn];
  if (sn == "") sn = err;
  if (sn == err) return err;
  for (int j = 0; j < k2; j++) sn += "*";
  for (int j = 0; j < k1; j++) {
    int O = sn.size() - 1;
    if (O + 1 == 0 || sn[O] != '*') return err;
    sn.erase(O, 1);
  }
  return sn;
};
int main() {
  int n;
  scanf("%d", &n);
  p["void"] = "void";
  p[err] = err;
  for (int i = 0; i < n; i++) {
    string s, s1, s2;
    cin >> s >> s1;
    if (s == "typedef") {
      cin >> s2;
      string sn = op(s1);
      p[s2] = sn;
    } else {
      string sn = op(s1);
      cout << sn << endl;
    }
  }
  return 0;
}
