#include <bits/stdc++.h>
using namespace std;
map<string, string> m;
string eval(string& s) {
  int c = 0;
  for (c = 0; c < s.size(); c++)
    if (s[c] != '&') break;
  int i;
  for (i = c; i < s.size(); i++)
    if (s[i] == '*') break;
  string str = s.substr(c, i - c);
  int rem = s.size() - i;
  if (str == "void") {
    rem = rem - c;
    if (rem < 0) return "errtype";
    return "void" + string(rem, '*');
  }
  if (m.find(str) == m.end()) return "errtype";
  str = m[str];
  if (str == "errtype") return "errtype";
  for (i = str.size() - 1; i > -1; i--)
    if (str[i] == '*') rem++;
  rem = rem - c;
  if (rem < 0) return "errtype";
  return "void" + string(rem, '*');
}
int main() {
  int n;
  string op, A, B;
  while (cin >> n) {
    m.clear();
    while (n--) {
      cin >> op;
      if (op == "typeof") {
        cin >> A;
        cout << eval(A) << endl;
      } else {
        cin >> A >> B;
        m[B] = eval(A);
      }
    }
  }
  return 0;
}
