#include <bits/stdc++.h>
std::map<std::string, int> a;
int main() {
  int n;
  std::cin >> n;
  for (int ii = 0; ii < n; ++ii) {
    std::string tp, A, B;
    std::cin >> tp >> A;
    int f1 = 0;
    int f2 = 0;
    while (*A.begin() == '&') {
      ++f1;
      A.erase(A.begin(), A.begin() + 1);
    }
    while (*A.rbegin() == '*') {
      ++f2;
      A.erase(A.end() - 1, A.end());
    }
    int c = 0;
    if (A == "errtype" || a.find(A) == a.end() && A != "void" || a[A] < 0) {
      c = -1;
    } else {
      c = a[A];
      c += f2 - f1;
      if (c < 0) {
        c = -1;
      }
    }
    if (tp == "typedef") {
      std::cin >> B;
      a[B] = c;
    } else {
      std::string ans = "void";
      if (c < 0) {
        ans = "errtype";
      } else {
        for (int i = 0; i < c; ++i) {
          ans += "*";
        }
      }
      std::cout << ans << std::endl;
    }
  }
  return 0;
}
