#include <bits/stdc++.h>
using namespace std;
map<string, int> types;
int count(const string &data) {
  int amps = 0, stars = 0, i, j;
  for (i = 0; i < (int)data.size() && data[i] == '&'; i++, amps++)
    ;
  for (j = data.size() - 1; j >= 0 && data[j] == '*'; j--, stars++)
    ;
  string t = data.substr(i, j - i + 1);
  if (!types.count(t) || types[t] == -1) return -1;
  int answer = types[t];
  answer += stars - amps, answer = max(-1, answer);
  return answer;
}
int n;
string command, a, b;
int main() {
  cin >> n;
  types["void"] = 0, types["errtype"] = -1;
  for (int i = 0; i < n; i++) {
    cin >> command >> a;
    if (command == "typedef")
      cin >> b, types[b] = count(a);
    else {
      int p = count(a);
      if (p == -1)
        cout << "errtype" << endl;
      else {
        cout << "void";
        for (int i = 0; i < p; i++) cout << "*";
        cout << endl;
      }
    }
  }
  return 0;
}
