#include <bits/stdc++.h>
using namespace std;
int main() {
  map<string, int> M;
  M["void"] = 0;
  M["errtype"] = -1;
  int n;
  cin >> n;
  string ins;
  for (int cas = 0; cas < n; cas++) {
    cin >> ins;
    if (ins == "typeof") {
      string s;
      cin >> s;
      int amp = 0, ast = 0;
      for (int i = 0; i < s.size(); i++)
        if (s[i] == '&') ++amp;
      for (int i = 0; i < s.size(); i++)
        if (s[i] == '*') ++ast;
      for (int i = 0; i < s.size(); i++) {
        if (s[i] != '&') {
          s = s.substr(i, int(s.size()) - amp - ast);
          break;
        }
      }
      if (M.find(s) == M.end() or M[s] < 0 or M[s] + ast - amp < 0)
        cout << "errtype" << endl;
      else {
        cout << "void";
        for (int k = 0; k < M[s] + ast - amp; k++) cout << '*';
        cout << endl;
      }
    } else {
      string A, B;
      cin >> A >> B;
      int amp = 0, ast = 0;
      for (int i = 0; i < A.size(); i++)
        if (A[i] == '&') ++amp;
      for (int i = 0; i < A.size(); i++)
        if (A[i] == '*') ++ast;
      for (int i = 0; i < A.size(); i++) {
        if (A[i] != '&') {
          A = A.substr(i, int(A.size()) - amp - ast);
          break;
        }
      }
      if (M.find(A) == M.end() or M[A] < 0)
        M[B] = -1;
      else
        M[B] = max(-1, M[A] + ast - amp);
    }
  }
}
