#include <bits/stdc++.h>
const double pi = acos(-1);
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int MAXN = 1e6 + 5;
const double eps = 1e-9;
using namespace std;
map<string, int> m;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  m["void"] = 0;
  m["errtype"] = -INF;
  for (int i = 0; i < n; i++) {
    string tmp, a, b;
    cin >> tmp >> a;
    if (strcmp(tmp.c_str(), "typedef") == 0) {
      cin >> b;
      int l = 0, r = 0;
      for (; l < a.length() && a[l] == '&'; l++)
        ;
      for (; r < a.length() && a[a.length() - r - 1] == '*'; r++)
        ;
      if (m.find(a.substr(l, a.length() - r - l)) == m.end()) continue;
      int val = m[a.substr(l, a.length() - r - l)] + r - l;
      if (val < 0) val = -INF;
      m[b] = val;
    } else {
      int l = 0, r = 0;
      for (; l < a.length() && a[l] == '&'; l++)
        ;
      for (; r < a.length() && a[a.length() - r - 1] == '*'; r++)
        ;
      if (m.find(a.substr(l, a.length() - r - l)) == m.end()) {
        cout << "errtype\n";
        continue;
      }
      int val = m[a.substr(l, a.length() - r - l)] + r - l;
      if (val < 0)
        cout << "errtype\n";
      else {
        cout << "void";
        for (int j = 0; j < val; j++) cout << "*";
        cout << "\n";
      }
    }
  }
  return 0;
}
