#include <bits/stdc++.h>
using namespace std;
map<string, pair<int, bool> > mp;
int main() {
  int n;
  cin >> n;
  mp["void"] = make_pair(0, true);
  string inp[3];
  pair<int, bool> fin, t;
  fin.first = 0;
  fin.second = false;
  for (int i = 0; i < n; ++i) {
    cin >> inp[0];
    if (inp[0][4] == 'd') {
      cin >> inp[1] >> inp[2];
      fin.second = true;
      int len = (int)inp[1].size();
      int l, r;
      int j = 0;
      for (; j < len; ++j) {
        if (inp[1][j] != '&') break;
      }
      l = j;
      for (r = 0; j < len; ++j, ++r) {
        if (inp[1][j] == '*') break;
      }
      t.first = len - r - l - l;
      string ts = inp[1].substr(l, r);
      if (ts == "void") {
        fin.first = t.first;
        if (fin.first < 0) fin.second = false;
        mp[inp[2]] = fin;
      } else {
        if (mp[ts].second == false) {
          fin.first = 0;
          fin.second = false;
        } else {
          fin.first = mp[ts].first + t.first;
          if (fin.first < 0) fin.second = false;
        }
        mp[inp[2]] = fin;
      }
    } else {
      cin >> inp[1];
      int len = (int)inp[1].size();
      int l, r;
      int j = 0;
      for (; j < len; ++j) {
        if (inp[1][j] != '&') break;
      }
      l = j;
      for (r = 0; j < len; ++j, ++r) {
        if (inp[1][j] == '*') break;
      }
      t.first = len - r - l - l;
      string ts = inp[1].substr(l, r);
      if (t.first + mp[ts].first < 0 || mp[ts].second == false) {
        cout << "errtype" << endl;
      } else {
        string op((mp[ts].first + t.first), '*');
        cout << "void" << op << endl;
      }
    }
  }
  return 0;
}
