#include <bits/stdc++.h>
using namespace std;
map<string, int> tps;
map<string, int>::iterator it;
int n;
void trim(string& s, int& kimp, int& kst) {
  string tmp = "";
  int len = s.length();
  int i = 0;
  kimp = 0;
  while (s[i] == '&') {
    kimp++;
    i++;
  }
  while (i < len && s[i] != '*') {
    tmp += s[i];
    i++;
  }
  kst = 0;
  while (i < len && s[i] == '*') {
    kst++;
    i++;
  }
  s = tmp;
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    string tp;
    cin >> tp;
    if (tp == "typeof") {
      cin >> tp;
      int kimp, kst;
      trim(tp, kimp, kst);
      if (tp != "void" && tps.find(tp) == tps.end()) {
        cout << "errtype" << endl;
      } else {
        int k;
        if (tp != "void") {
          k = tps[tp];
        } else
          k = 0;
        if (k == -1) {
          cout << "errtype" << endl;
        } else {
          k += kst;
          k -= kimp;
          if (k < 0)
            cout << "errtype" << endl;
          else {
            cout << "void";
            for (int i = 0; i < k; i++) cout << "*";
            cout << endl;
          }
        }
      }
    } else {
      string some, what;
      cin >> some >> what;
      int kimp = 0, kst = 0;
      trim(some, kimp, kst);
      if (some != "void" && tps.find(some) == tps.end()) {
        tps[what] = -1;
      } else {
        int k;
        if (some != "void") {
          k = tps[some];
        } else
          k = 0;
        if (k == -1) {
          tps[what] = -1;
        } else {
          k += kst;
          k -= kimp;
          if (k < 0)
            tps[what] = -1;
          else
            tps[what] = k;
        }
      }
    }
  }
  return 0;
}
