#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const double PI = acos(-1.0);
const int INF = 1e9 + 7;
const int MAXN = int(2e5 + 7);
int n;
map<string, string> m;
string go(string second) {
  int l = 0, r = second.size() - 1;
  while (second[l] == '&') l++;
  while (second[r] == '*') r--;
  if (m.find(second.substr(l, r - l + 1)) == m.end()) return "errtype";
  string t = m[second.substr(l, r - l + 1)];
  if (t == "errtype") return "errtype";
  for (int i = 0; i < l; i++) t = '&' + t;
  for (int i = r + 1; i < second.size(); i++) t = t + '*';
  l = 0, r = t.size() - 1;
  while (t[l] == '&' && t[r] == '*') l++, r--;
  if (t[l] == '&') return "errtype";
  return t.substr(l, r - l + 1);
}
int main() {
  cin >> n;
  m["void"] = "void";
  m["errtype"] = "errtype";
  for (int i = 0; i < n; i++) {
    string second, a, b;
    cin >> second;
    if (second[4] == 'd') {
      cin >> a >> b;
      a = go(a);
      m[b] = a;
    } else {
      cin >> a;
      cout << go(a) << endl;
    }
  }
  return 0;
}
