#include <bits/stdc++.h>
using namespace std;
int n;
map<string, int> mp;
int cnt(string s) {
  int a = 0, b = 0, c = 0;
  while (a < s.size() && s[a] == '&') a++, c--;
  b = s.size() - 1;
  while (b >= 0 && s[b] == '*') b--, c++;
  string t = "";
  for (int i = a; i <= b; i++) t += s[i];
  s = t;
  if (!mp.count(s)) return -1;
  int x = mp[t];
  if (x == -1) return -1;
  x += c;
  if (x < 0) return -1;
  return x;
}
int main() {
  cin >> n;
  mp["void"] = 0;
  for (int i = 0; i < n; i++) {
    string v;
    cin >> v;
    if (v == "typeof") {
      string s;
      cin >> s;
      int m = cnt(s);
      if (m == -1)
        cout << "errtype" << endl;
      else {
        cout << "void";
        for (int j = 0; j < m; j++) cout << '*';
        cout << endl;
      }
    } else {
      string s1, t1;
      cin >> s1 >> t1;
      mp[t1] = cnt(s1);
    }
  }
  return 0;
}
