#include <bits/stdc++.h>
using namespace std;
void strip(string& s, int& amps, int& stars) {
  int i = 0;
  while (s[i] == '&') {
    i++;
  }
  amps = i;
  int j = s.size() - 1;
  while (s[j] == '*') {
    j--;
  }
  stars = s.size() - 1 - j;
  s = s.substr(i, j - i + 1);
}
int main() {
  ios::sync_with_stdio(false);
  map<string, int> m;
  m["void"] = 0;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    if (s == "typedef") {
      string t, x;
      cin >> t >> x;
      int amps, stars;
      strip(t, amps, stars);
      if (!m.count(t) || m[t] + stars < amps) {
        m.erase(x);
      } else {
        m[x] = m[t] - amps + stars;
      }
    } else {
      string t;
      cin >> t;
      int amps, stars;
      strip(t, amps, stars);
      if (!m.count(t) || m[t] + stars < amps) {
        cout << "errtype" << endl;
      } else {
        cout << "void";
        for (int j = 0; j < m[t] - amps + stars; j++) {
          cout << '*';
        }
        cout << endl;
      }
    }
  }
  return 0;
}
