#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  map<string, int> Map;
  Map.clear();
  Map["void"] = 0;
  for (int i = 1; i <= N; ++i) {
    string Cmd, A, B;
    cin >> Cmd >> A;
    int h = 0, t = A.length();
    while (A[h] == '&') ++h;
    while (A[t - 1] == '*') --t;
    string O = "";
    for (int k = h; k < t; ++k) O += A[k];
    if (Cmd == "typedef") {
      cin >> B;
      int val = -10000000;
      if (Map.count(O)) val = Map[O];
      val -= h;
      val += A.length() - t;
      if (val >= 0)
        Map[B] = val;
      else {
        if (Map.count(B)) Map.erase(B);
      }
    } else {
      int val = -10000000;
      if (Map.count(O)) val = Map[O];
      val -= h;
      val += A.length() - t;
      if (val >= 0) {
        cout << "void";
        for (int k = 1; k <= val; ++k) cout << "*";
        cout << endl;
      } else
        cout << "errtype" << endl;
    }
  }
}
