#include <bits/stdc++.h>
using namespace std;
map<string, int> m;
int solve(string b) {
  int ans = 0;
  int n = b.length();
  string t = "";
  for (int i = 0; i < n; i++)
    if (b[i] == '&') {
      if (t != "") {
        if (m.count(t)) return -11111111;
        ans += m[t];
      }
      t = "";
      ans--;
    } else if (b[i] == '*') {
      if (t != "") {
        if (m.count(t) == 0) return -11111111;
        ans += m[t];
      }
      t = "";
      ans++;
    } else
      t += b[i];
  if (t != "") {
    if (m.count(t) == 0) return -11111111;
    ans += m[t];
  }
  t = "";
  if (ans < 0) return -11111111;
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n;
  m["void"] = 0;
  m["*"] = 1;
  cin >> n;
  while (n--) {
    string a, b, c;
    cin >> a;
    if (a == "typedef") {
      cin >> b >> c;
      int pos = solve(b);
      m[c] = pos;
    } else {
      cin >> b;
      int pos = solve(b);
      if (pos < 0) {
        cout << "errtype\n";
        continue;
      } else {
        cout << "void";
        for (int i = 0; i < pos; i++) cout << "*";
        cout << "\n";
      }
    }
  }
  return 0;
}
