#include <bits/stdc++.h>
using namespace std;
map<string, int> val;
int pre, aft;
string go(string s) {
  pre = aft = 0;
  while (!s.empty()) {
    if (s[s.size() - 1] != '*') break;
    s.pop_back();
    aft++;
  }
  reverse(s.begin(), s.end());
  while (!s.empty()) {
    if (s[s.size() - 1] != '&') break;
    s.pop_back();
    pre++;
  }
  reverse(s.begin(), s.end());
  return s;
}
int main() {
  ios::sync_with_stdio(0);
  int n;
  cin >> n;
  string ty, s1, s2;
  val["void"] = 0;
  val["errtype"] = -1;
  for (int i = 0; i < n; i++) {
    cin >> ty >> s1;
    if (ty == "typedef") {
      cin >> s2;
      s1 = go(s1);
      if (!val.count(s1)) val[s1] = -1;
      int num1 = val[s1];
      if (num1 != -1) {
        num1 += aft;
        num1 -= pre;
      }
      num1 = max(num1, -1);
      val[s2] = num1;
    } else {
      s1 = go(s1);
      if (!val.count(s1)) val[s1] = -1;
      if (val[s1] == -1) {
        cout << "errtype\n";
        continue;
      }
      int num1 = val[s1];
      num1 += aft;
      num1 -= pre;
      if (num1 < 0) {
        cout << "errtype\n";
        continue;
      }
      cout << "void";
      for (int i = 0; i < num1; i++) cout << "*";
      cout << "\n";
    }
  }
  return 0;
}
