#include <bits/stdc++.h>
using namespace std;
map<string, int> m;
string s, a, b;
int n;
int main() {
  cin >> n;
  m["void"];
  m["errtype"] = -1;
  while (n--) {
    cin >> s;
    if (s == "typedef") {
      string t = "";
      int cur = 0;
      cin >> a >> b;
      for (int i = 0; i < a.size(); i++) {
        if (isalpha(a[i]))
          t += a[i];
        else if (a[i] == '&')
          cur--;
        else
          cur++;
      }
      if (m.find(t) == m.end() || m[t] < 0 || m[t] + cur < 0)
        m[b] = -1;
      else
        m[b] = m[t] + cur;
    } else {
      cin >> a;
      string t = "";
      int cur = 0;
      for (int i = 0; i < a.size(); i++) {
        if (isalpha(a[i]))
          t += a[i];
        else if (a[i] == '&')
          cur--;
        else
          cur++;
      }
      if (m.find(t) == m.end() || m[t] < 0 || m[t] + cur < 0)
        puts("errtype");
      else
        cout << "void" << string(m[t] + cur, '*') << endl;
    }
  }
  return 0;
}
