#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e4 + 1;
const double EPS = 1e-7;
string getClear(string a) {
  string ans;
  for (char c : a) {
    if (c != '*' && c != '&') {
      ans.push_back(c);
    }
  }
  return ans;
}
string getFinal(string a) {
  int b = 0;
  if (getClear(a) == "errtype") {
    return "errtype";
  }
  while (a[b] == '&' && a.back() == '*') {
    ++b, a.pop_back();
  }
  int cntAmp = 0;
  for (int i = b; i < a.size(); ++i) {
    if (a[i] != '&') {
      break;
    }
    ++cntAmp;
  }
  if (cntAmp > 0) {
    return "errtype";
  }
  return a.substr(b);
}
string getAmpersands(string a) {
  int b = 0, e = 0;
  while (a[b] == '&' && a.back() == '*') {
    ++b, a.pop_back();
  }
  for (e = 0; e < a.size(); ++e) {
    if (a[e] != '&') {
      break;
    }
  }
  return a.substr(b, e - b);
}
string getStars(string a) {
  int b = 0;
  while (a[b] == '&' && a.back() == '*') {
    ++b, a.pop_back();
  }
  int e;
  for (e = a.size(); e >= 0; --e) {
    if (a[e - 1] != '*') {
      break;
    }
  }
  return a.substr(e);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  map<string, string> mtypeof;
  mtypeof["void"] = "void";
  mtypeof["errtype"] = "errtype";
  for (int i = 0; i < n; ++i) {
    string op;
    cin >> op;
    if (op == "typedef") {
      string A, B;
      cin >> A >> B;
      string a = getClear(A);
      if (a == "errtype") {
        mtypeof[B] = a;
      } else if (a == "void") {
        mtypeof[B] = getFinal(A);
      } else {
        if (mtypeof.find(a) == mtypeof.end()) {
          mtypeof[B] = "errtype";
        } else {
          mtypeof[B] = getFinal(getAmpersands(A) + mtypeof[a] + getStars(A));
        }
      }
    } else {
      string A;
      cin >> A;
      string a = getClear(A);
      if (mtypeof.find(a) == mtypeof.end()) {
        cout << "errtype" << '\n';
      } else {
        cout << getFinal(getAmpersands(A) + mtypeof[a] + getStars(A)) << '\n';
      }
    }
  }
}
