#include <bits/stdc++.h>
using namespace std;
const int M = 100000 + 10;
map<string, string> Type;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    if (s == "typedef") {
      string a, b;
      cin >> a >> b;
      string t = "";
      int id = 0;
      while (id < a.length() && a[id] == '&') {
        id++;
      }
      int num_ne = id;
      while (id < a.length() && a[id] != '*') {
        t = t + a[id];
        id++;
      }
      int num_po = 0;
      while (id < a.length() && a[id] == '*') {
        num_po++;
        id++;
      }
      if (t == "void") {
        if (num_ne <= num_po) {
          Type[b] = "void";
          for (int j = 1; j <= num_po - num_ne; j++) {
            Type[b] = Type[b] + "*";
          }
        } else {
          Type[b] = "errtype";
        }
      }
      if (t == "errtype") {
        Type[b] = "errtype";
      }
      if (t != "errtype" && t != "void") {
        if (Type.find(t) != Type.end()) {
          if (Type[t] == "errtype") {
            Type[b] = "errtype";
          } else {
            int num = Type[t].length() - 4;
            if (num_ne <= num_po + num) {
              Type[b] = "void";
              for (int j = 1; j <= num_po + num - num_ne; j++) {
                Type[b] = Type[b] + "*";
              }
            } else {
              Type[b] = "errtype";
            }
          }
        } else {
          Type[b] = "errtype";
        }
      }
    } else {
      string a;
      cin >> a;
      string t = "";
      int id = 0;
      while (id < a.length() && a[id] == '&') {
        id++;
      }
      int num_ne = id;
      while (id < a.length() && a[id] != '*') {
        t = t + a[id];
        id++;
      }
      int num_po = 0;
      while (id < a.length() && a[id] == '*') {
        num_po++;
        id++;
      }
      if (t == "void") {
        if (num_ne <= num_po) {
          cout << "void";
          for (int j = 1; j <= num_po - num_ne; j++) {
            cout << "*";
          }
          cout << endl;
        } else {
          cout << "errtype" << endl;
        }
      } else {
        if (Type.find(t) == Type.end()) {
          cout << "errtype" << endl;
        } else {
          if (Type[t] == "errtype") {
            cout << "errtype" << endl;
          } else {
            int num = Type[t].length() - 4;
            if (num_ne <= num_po + num) {
              cout << "void";
              for (int j = 1; j <= num_po + num - num_ne; j++) {
                cout << "*";
              }
              cout << endl;
            } else {
              cout << "errtype" << endl;
            }
          }
        }
      }
    }
  }
  return 0;
}
