#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  map<string, int> M;
  M["void"] = 0;
  cin >> n;
  while (n--) {
    string a, b, c, v;
    int a_cnt = 0, s_cnt = 0;
    cin >> a >> b;
    if (a == "typedef") {
      cin >> c;
    }
    for (int i = 0; i < b.size(); i++) {
      if (b[i] == '&')
        a_cnt++;
      else if (b[i] == '*')
        s_cnt++;
      else
        v.append(1, b[i]);
    }
    if (a == "typedef") {
      if (M.find(v) == M.end()) {
        M[c] = -1;
      } else if (M[v] + s_cnt - a_cnt < 0 || M[v] < 0) {
        M[c] = -1;
      } else {
        M[c] = M[v] + s_cnt - a_cnt;
      }
    } else {
      if (M.find(v) == M.end()) {
        cout << "errtype\n";
      } else if (M[v] + s_cnt - a_cnt < 0 || M[v] < 0) {
        cout << "errtype\n";
      } else {
        cout << "void";
        for (int i = 0; i < M[v] + s_cnt - a_cnt; i++) {
          cout << "*";
        }
        cout << "\n";
      }
    }
  }
  return 0;
}
