#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T MIN(T a, T b) {
  return a < b ? a : b;
}
template <class T>
inline T MAX(T a, T b) {
  return a > b ? a : b;
}
template <class T>
inline void getInt(T& x) {
  char c;
  int mul = 1;
  while ((c = getchar()) != EOF) {
    if (c == '-') mul = -1;
    if (c >= '0' && c <= '9') {
      x = c - '0';
      break;
    }
  }
  if (c == EOF) {
    x = EOF;
    return;
  }
  while (c = getchar()) {
    if (c >= '0' && c <= '9') {
      x = (x << 1) + (x << 3) + (c - '0');
    } else
      break;
  }
  x *= mul;
}
int n;
map<string, string> m;
string query(string q) {
  int ast = 0, amp = 0;
  int ctr = 0, ctr2 = q.length() - 1;
  while (q[ctr] == '&') amp++, ctr++;
  while (q[ctr2] == '*') {
    ast++, ctr2--;
  }
  q = q.substr(ctr, q.length() - ast - amp);
  if (q == "void") {
    if (ast < amp) {
      return "errtype";
    } else {
      ast -= amp;
      for (int i = 0, _n = (ast); i < _n; i++) q += "*";
      return q;
    }
  } else if (q == "errtype" || m.find(q) == m.end()) {
    return "errtype";
  } else {
    string qq = query(m[q]);
    int ast1 = 0, amp1 = 0;
    int cctr = 0, cctr2 = qq.length() - 1;
    while (qq[cctr] == '&') amp1++, cctr++;
    while (qq[cctr2] == '*') ast1++, cctr2--;
    qq = qq.substr(cctr, qq.length() - ast1 - amp1);
    if (qq == "errtype") {
      return "errtype";
    }
    ast += ast1;
    amp += amp1;
    if (ast < amp) {
      return "errtype";
    } else {
      ast -= amp;
      string temp = qq;
      for (int i = 0, _n = (ast); i < _n; i++) qq += "*";
      return qq;
    }
  }
  return m[q];
}
int main() {
  getInt(n);
  m["void"] = "void";
  string a, b, c;
  for (int i = 0, _n = (n); i < _n; i++) {
    cin >> a;
    if (a == "typedef") {
      cin >> b >> c;
      m[c] = query(b);
    } else {
      cin >> b;
      cout << query(b) << endl;
    }
  }
}
