#include <bits/stdc++.h>
using namespace std;
int main() {
  int n = 0;
  cin >> n;
  map<string, int> m;
  m.insert(make_pair("void", 0));
  for (int i = 0; i < n; i++) {
    string s1, s2;
    cin >> s1 >> s2;
    int p0 = count(s2.begin(), s2.end(), '&'),
        p1 = count(s2.begin(), s2.end(), '*');
    string st(s2.begin() + p0, s2.end() - p1);
    if (s1 == "typeof") {
      if (m.count(st) == 0 || m[st] + p1 - p0 < 0 || m[st] < 0) {
        cout << "errtype" << endl;
      } else {
        cout << "void";
        for (int j = 0; j < m[st] + p1 - p0; j++) {
          cout << "*";
        }
        cout << endl;
      }
    } else {
      string s3;
      cin >> s3;
      if (m.count(st) == 0 || m[st] + p1 - p0 < 0 || m[st] < 0) {
        m[s3] = -1;
      } else {
        m[s3] = m[st] + p1 - p0;
      }
    }
  }
  return 0;
}
