#include <bits/stdc++.h>
using namespace std;
void divide(int& star, string& str) {
  int left = 0, right = 0, start = -1, end = str.length();
  for (int i = 0; i < str.length(); i++) {
    if (str[i] == '&')
      left++;
    else if (str[i] == '*') {
      right++;
      if (end == str.length()) end = i;
    } else {
      if (start == -1) start = i;
    }
  }
  if (start == -1) start = 0;
  str = string(str.begin() + start, str.begin() + end);
  star = right - left;
}
int main() {
  map<string, int> type;
  type["void"] = 0;
  type["errtype"] = -1;
  int cases;
  cin >> cases;
  while (cases--) {
    int star = 0;
    string str;
    cin >> str;
    if (!str.compare("typedef")) {
      string cpy, var;
      cin >> cpy >> var;
      divide(star, cpy);
      if (type.find(cpy) == type.end())
        type[var] = -1;
      else if (type[cpy] <= -1 || star + type[cpy] < 0)
        type[var] = -1;
      else
        type[var] = star + type[cpy];
    } else {
      string var;
      cin >> var;
      divide(star, var);
      if (type.find(var) == type.end())
        cout << "errtype" << endl;
      else if (type[var] <= -1 || star + type[var] < 0)
        cout << "errtype" << endl;
      else {
        cout << "void";
        for (int i = 0; i < type[var] + star; i++) cout << '*';
        cout << endl;
      }
    }
  }
  return 0;
}
