#include <bits/stdc++.h>
struct Node {
  int ast, amp;
  std::string val;
  Node() : ast(0), amp(0) {}
};
Node parse(const std::string& a) {
  Node node;
  int j;
  for (j = 0; j < (int)a.size(); ++j) {
    if (a[j] != '&') {
      break;
    }
  }
  node.amp = j;
  for (j = 0; j < (int)a.size(); ++j) {
    if (a[j] == '*') {
      break;
    }
  }
  node.val = a.substr(node.amp, j - node.amp);
  node.ast = a.size() - j;
  return node;
}
int main() {
  int n;
  std::cin >> n;
  std::map<std::string, Node> m;
  for (int i = 0; i < n; ++i) {
    std::string op;
    std::cin >> op;
    if (op == "typedef") {
      std::string a, b;
      std::cin >> a >> b;
      Node node = parse(a);
      if (node.val == "errtype" ||
          (node.val != "void" && m.count(node.val) == 0)) {
        node.val = "errtype";
        m[b] = node;
      } else if (node.val == "void") {
        if (node.amp > node.ast) {
          node.val = "errtype";
        } else {
          node.ast -= node.amp;
          node.amp = 0;
        }
        m[b] = node;
      } else {
        Node x = m[node.val];
        if (x.val == "errtype") {
          node.val = x.val;
        } else {
          node.ast += x.ast;
          if (node.amp > node.ast) {
            node.val = "errtype";
          } else {
            node.val = "void";
            node.ast -= node.amp;
            node.amp = 0;
          }
        }
        m[b] = node;
      }
    } else {
      std::string a;
      std::cin >> a;
      Node node = parse(a);
      if (node.val == "errtype" ||
          (node.val != "void" && m.count(node.val) == 0)) {
        node.val = "errtype";
      } else if (node.val == "void") {
      } else {
        Node x = m[node.val];
        if (x.val == "errtype") {
          node.val = x.val;
        } else {
          node.ast += x.ast;
          if (node.amp > node.ast) {
            node.val = "errtype";
          } else {
            node.ast -= node.amp;
            node.amp = 0;
          }
        }
      }
      if (node.val == "errtype") {
        std::cout << "errtype" << std::endl;
      } else {
        std::cout << "void" << std::string(node.ast, '*') << std::endl;
      }
    }
  }
}
