#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
const double EPS = 1e-9;
const double PI = 3.1415926535897932384626433832795;
double dis(complex<double> p1, complex<double> p2) {
  return sqrt((p1.real() - p2.real()) * (p1.real() - p2.real()) +
              (p1.imag() - p2.imag()) * (p1.imag() - p2.imag()));
}
map<string, pair<int, string> > mp;
int main() {
  int n;
  cin >> n;
  mp["void"] = pair<int, string>(0, "void");
  for (int i = 0; i < n; i++) {
    string a, b, c;
    cin >> a >> b;
    if (a == "typeof") {
      int ca = 0;
      while (ca < (int)b.size() && b[ca] == '&') ca++;
      int cb = b.size();
      while (cb > 0 && b[cb - 1] == '*') cb--;
      string name(b.begin() + ca, b.begin() + cb);
      int cnt = (b.size() - cb) - ca + mp[name].first;
      if (mp[name].second == "void" && cnt >= 0) {
        cout << "void";
        for (int i = 0; i < cnt; i++) {
          cout << "*";
        }
        cout << endl;
      } else {
        cout << "errtype" << endl;
      }
    } else {
      cin >> c;
      int ca = 0;
      while (ca < (int)b.size() && b[ca] == '&') ca++;
      int cb = b.size();
      while (cb > 0 && b[cb - 1] == '*') cb--;
      string name(b.begin() + ca, b.begin() + cb);
      if (mp[name].second != "void") {
        mp[c] = pair<int, string>(0, "errtype");
      } else {
        int cnt = mp[name].first + (b.size() - cb) - ca;
        if (cnt < 0) {
          mp[c] = pair<int, string>(0, "errtype");
        } else {
          mp[c] = pair<int, string>(cnt, "void");
        }
      }
    }
  }
  return 0;
}
