#include <bits/stdc++.h>
template <typename T>
T inline SQR(const T& a) {
  return a * a;
}
template <typename T>
T inline ABS(const T& a) {
  return a < 0 ? -a : a;
}
template <typename T>
T inline MIN(const T& a, const T& b) {
  if (a < b) return a;
  return b;
}
template <typename T>
T inline MAX(const T& a, const T& b) {
  if (a > b) return a;
  return b;
}
using namespace std;
int main(int argc, char* argv[]) {
  ios::sync_with_stdio(false);
  int n;
  map<string, int> type;
  type["void"] = 0;
  type["errtype"] = -1;
  cin >> n;
  string wut, A, B;
  while (n--) {
    cin >> wut;
    if (wut[4] == 'd') {
      cin >> A >> B;
      int i = 0, ind = 0;
      while (A[i] == '&') ind--, i++;
      int j = (int)A.size() - 1;
      while (A[j] == '*') ind++, j--;
      string olda = A.substr(i, j - i + 1);
      if (type.find(olda) == type.end() || type[olda] < 0)
        type[B] = -1;
      else
        type[B] = type[olda] + ind;
    } else {
      cin >> A;
      int i = 0, ind = 0;
      while (A[i] == '&') ind--, i++;
      int j = (int)A.size() - 1;
      while (A[j] == '*') ind++, j--;
      string olda = A.substr(i, j - i + 1);
      int hm = -1;
      if (type.find(olda) == type.end() || type[olda] < 0)
        hm = -1;
      else
        hm = type[olda] + ind;
      if (hm < 0) {
        cout << "errtype\n";
      } else {
        cout << "void";
        while (hm--) cout << "*";
        cout << "\n";
      }
    }
  }
  return 0;
}
