#include <bits/stdc++.h>
using namespace std;
map<string, int> m;
string c;
int Work(string x) {
  int cnt = 0;
  string &a = c;
  a = "";
  for (int i = 0; i < x.size(); i++) {
    if (x[i] == '*')
      cnt++;
    else if (x[i] == '&')
      cnt--;
    else
      a += x[i];
  }
  if (m.find(a) != m.end()) cnt += m[a];
  return cnt;
}
int main() {
  int n;
  cin >> n;
  m["void"] = 0;
  for (int i = 0; i < n; i++) {
    string a;
    cin >> a;
    if (a == "typedef") {
      string x, y;
      cin >> x >> y;
      m[y] = Work(x) >= 0 && m.find(c) != m.end() ? Work(x) : -9999999;
    } else {
      string x;
      cin >> x;
      int y = Work(x);
      if (y >= 0 && m.find(c) != m.end()) {
        cout << "void";
        for (int i = 0; i < y; i++) cout << "*";
        puts("");
      } else
        puts("errtype");
    }
  }
  return 0;
}
