#include <bits/stdc++.h>
using namespace std;
map<string, int> a;
pair<string, int> get(string s) {
  int c1 = 0, c2 = 0;
  for (int i = 0; i < (int)(s.length()); i++)
    if (s[i] == '&')
      c1++;
    else if (s[i] == '*')
      c2++;
  return make_pair(s.substr(c1, s.length() - c1 - c2), c2 - c1);
};
int main() {
  a["void"] = 0;
  a["errtype"] = -1;
  int n;
  string s1, s2, t;
  cin >> n;
  for (int i = 0; i < (int)(n); i++) {
    cin >> t >> s1;
    pair<string, int> q = get(s1);
    if (t == "typeof") {
      if (!a.count(q.first) || a[q.first] == -1 || a[q.first] + q.second < 0)
        cout << "errtype\n";
      else {
        cout << "void";
        for (int i = a[q.first] + q.second; i; i--) cout << "*";
        cout << endl;
      }
    } else {
      cin >> s2;
      pair<string, int> t = get(s1);
      if (!a.count(t.first) || a[t.first] == -1 || a[t.first] + t.second < 0)
        a[s2] = -1;
      else
        a[s2] = a[t.first] + t.second;
    }
  }
};
