#include <bits/stdc++.h>
using namespace std;
struct points {
  int t;
  bool f;
};
map<string, points> m;
struct reval {
  string s;
  int res;
};
reval cnt(string s) {
  reval tmp;
  tmp.s = "";
  int i = 0, sum1 = 0, sum2 = 0;
  while (s[i] == '&') i++, sum1++;
  while (i < s.size() && s[i] != '*') tmp.s += s[i], i++;
  sum2 = s.size() - i;
  tmp.res = sum2 - sum1;
  return tmp;
}
void def() {
  string st1, st2;
  cin >> st1 >> st2;
  reval tmp = cnt(st1);
  if (m.find(tmp.s) == m.end() || tmp.res + m[tmp.s].t < 0 || m[tmp.s].f) {
    m[st2].f = true;
    return;
  }
  m[st2].f = false;
  m[st2].t = tmp.res + m[tmp.s].t;
  return;
}
void of() {
  string t;
  cin >> t;
  reval tmp = cnt(t);
  if (m.find(tmp.s) == m.end() || m[tmp.s].f) {
    cout << "errtype\n";
    m[tmp.s].f = true;
    return;
  }
  int times = m[tmp.s].t + tmp.res;
  if (times < 0) {
    cout << "errtype\n";
    return;
  }
  cout << "void";
  for (int i = 1; i <= times; i++) cout << "*";
  cout << endl;
  return;
}
int main() {
  int p;
  string s, t;
  m["void"].t = 0;
  m["void"].f = false;
  cin >> p;
  while (p--) {
    cin >> s;
    if (s == "typedef")
      def();
    else
      of();
  }
  return 0;
}
