#include <bits/stdc++.h>
using namespace std;
map<string, pair<int, int> > mp;
void printit(pair<int, int> p) {
  if (p.first == 1) {
    cout << "errtype" << endl;
  } else {
    cout << "void";
    while (p.second--) {
      cout << '*';
    }
    cout << endl;
  }
}
pair<int, int> gaotype(string s) {
  int nat = 0, nst = 0;
  while (!s.empty() && s[0] == '&') {
    ++nat;
    s = s.substr(1);
  }
  while (!s.empty() && s[s.size() - 1] == '*') {
    ++nst;
    s = s.substr(0, s.size() - 1);
  }
  if (s == "errtype") {
    return make_pair(1, 0);
  } else if (s == "void") {
    if (nst >= nat) {
      return make_pair(0, nst - nat);
    } else {
      return make_pair(1, 0);
    }
  } else {
    if (!mp.count(s)) {
      return make_pair(1, 0);
    } else {
      pair<int, int> p = mp[s];
      p.second -= nat;
      p.second += nst;
      if (p.second < 0) {
        p.first = 1;
        p.second = 0;
      }
      return p;
    }
  }
}
int main() {
  int n;
  cin >> n;
  while (n--) {
    string a, b, c;
    cin >> a >> b;
    if (a == "typeof") {
      printit(gaotype(b));
    } else {
      cin >> c;
      mp[c] = gaotype(b);
    }
  }
  return 0;
}
