#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:10000000")
using namespace std;
template <typename T>
inline T abs(T a) {
  return ((a < 0) ? -a : a);
}
template <typename T>
inline T sqr(T a) {
  return a * a;
}
const int INF = (int)1E9 + 7;
const long double EPS = 1E-9;
const long double PI = 3.1415926535897932384626433832795;
map<string, string> ans;
int n;
const string err = "errtype", vd = "void";
string get(string d) {
  int c1 = 0, c2 = 0;
  string ok;
  for (int i = 0; i < int(int((d).size())); ++i) {
    c1 += (d[i] == '&'), c2 += (d[i] == '*');
    if (d[i] != '&' && d[i] != '*') ok += d[i];
  }
  if (ans.count(ok) == 0) return err;
  ok = ans[ok];
  if (ok == err) return err;
  int c3 = 0;
  for (int i = 0; i < int(int((ok).size())); ++i) c3 += (ok[i] == '*');
  if (c3 + c2 < c1)
    return err;
  else {
    string res;
    for (int i = 0; i < int(int((ok).size())); ++i)
      if (ok[i] != '*') res += ok[i];
    for (int i = 0; i < int(c3 + c2 - c1); ++i) res += '*';
    return res;
  }
}
int main() {
  ans[vd] = vd;
  ans[err] = err;
  cin >> n;
  for (int i = 0; i < int(n); ++i) {
    string t;
    cin >> t;
    if (t == "typedef") {
      string x, y;
      cin >> x >> y;
      ans[y] = get(x);
    } else {
      string x;
      cin >> x;
      cout << get(x) << endl;
    }
  }
  return 0;
}
