#include <bits/stdc++.h>
using namespace std;
const int N = 1e2 + 9;
string arr[N];
map<string, string> values;
string getAmp(string word) {
  int i = 0;
  string s = "";
  while (i < word.size()) {
    if (word[i] != '&') break;
    s += '&';
    i++;
  }
  return s;
}
string getVariableName(string word) {
  int i = 0;
  string s = "";
  while (i < word.size()) {
    if (word[i] != '&') break;
    i++;
  }
  while (i < word.size()) {
    if (word[i] == '*') break;
    s += word[i];
    i++;
  }
  return s;
}
string getAst(string word) {
  int i = 0;
  string s = "";
  while (i < word.size()) {
    if (word[i] != '&') break;
    i++;
  }
  while (i < word.size()) {
    if (word[i] == '*') break;
    i++;
  }
  while (i < word.size()) {
    s += word[i];
    i++;
  }
  return s;
}
string isValid(string amp, string value, string astric) {
  if (value == "errtype" || amp.size() > astric.size()) return "errtype";
  int countAst = astric.size() - amp.size();
  for (int i = 0; i < countAst; i++) {
    value += '*';
  }
  return value;
}
string evaluate(string source) {
  string variableName = getVariableName(source);
  if (values.count(variableName) == 0) return "errtype";
  string variableValue = values[variableName];
  string newValue = isValid(getAmp(source) + getAmp(variableValue),
                            getVariableName(variableValue),
                            getAst(variableValue) + getAst(source));
  return newValue;
}
int main() {
  int n;
  cin >> n;
  values["void"] = "void";
  values["errtype"] = "errtype";
  for (size_t i = 0; i < n; i++) {
    string op, source, target;
    cin >> op;
    cin >> source;
    string v = evaluate(source);
    if (op == "typeof") {
      cout << v << '\n';
    } else {
      cin >> target;
      values[target] = v;
    }
  }
}
