#include <bits/stdc++.h>
using namespace std;
unordered_map<string, string> hash_;
vector<string> split(string line) {
  vector<string> result;
  string tmp = "";
  for (char ch : line) {
    if (ch == ' ') {
      if (tmp != "") {
        result.push_back(tmp);
        tmp = "";
      }
    } else
      tmp += ch;
  }
  if (tmp != "") result.push_back(tmp);
  return result;
}
string parse(string line) {
  string left = "", result = "", right = "";
  for (char ch : line) {
    if (ch == '*')
      right += ch;
    else if (ch == '&')
      left += ch;
    else if (ch != ' ')
      result += ch;
  }
  if (hash_.find(result) == hash_.end()) return "errtype";
  line = left + hash_[result] + right;
  left = "", result = "", right = "";
  for (char ch : line) {
    if (ch == '*')
      right += ch;
    else if (ch == '&')
      left += ch;
    else if (ch != ' ')
      result += ch;
  }
  if (hash_.find(result) == hash_.end() || result == "errtype" ||
      left.size() > right.size())
    return "errtype";
  return result + string(right.size() - left.size(), '*');
}
int main() {
  hash_["void"] = "void";
  hash_["errtype"] = "errtype";
  int n;
  string line;
  cin >> n;
  cin.get();
  while (n-- > 0) {
    getline(cin, line);
    vector<string> words = split(line);
    if (words[0] == "typeof")
      cout << parse(words[1]) << endl;
    else
      hash_[words[2]] = parse(words[1]);
  }
  return 0;
}
