#include <bits/stdc++.h>
using namespace std;
int main() {
  map<string, int> tipus;
  tipus["void"] = 0;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string op;
    cin >> op;
    string name;
    cin >> name;
    int i1 = 0;
    while (name[i1] == '&') i1++;
    int i2 = int(name.size());
    while (name[i2 - 1] == '*') i2--;
    int menys = i1;
    int mes = int(name.size()) - i2;
    name = name.substr(i1, i2 - i1);
    int t;
    if (tipus.find(name) != tipus.end())
      t = tipus[name];
    else
      t = -1;
    if (t >= 0) t += mes - menys;
    if (op == "typeof") {
      if (t < 0)
        cout << "errtype" << endl;
      else
        cout << "void" << string(t, '*') << endl;
    } else {
      cin >> name;
      tipus[name] = t;
    }
  }
}
