#include <bits/stdc++.h>
inline void swap(int &a, int &b) {
  int tmp = a;
  a = b;
  b = tmp;
}
inline void swap(long long &a, long long &b) {
  long long tmp = a;
  a = b;
  b = tmp;
}
inline void swap(long double &a, long double &b) {
  long double tmp = a;
  a = b;
  b = tmp;
}
inline long double ABS(const long double &val) { return val < 0 ? -val : val; }
inline long long MAX(const long long &a, const long long &b) {
  return a > b ? a : b;
}
inline int MAX(const int &a, const int &b) { return a > b ? a : b; }
inline long long MIN(const long long &a, const long long &b) {
  return a < b ? a : b;
}
inline int MIN(const int &a, const int &b) { return a < b ? a : b; }
inline long double MAX(const long double &a, const long double &b) {
  return a > b ? a : b;
}
inline long double MIN(const long double &a, const long double &b) {
  return a < b ? a : b;
}
const int INTinf = 2147483647;
const int nINTinf = 0 - 2147483648;
using namespace std;
struct node {
  bool type;
  int idx;
  node() {}
  node(bool type, int idx) {
    this->type = type;
    this->idx = idx;
    if (idx < 0) this->type = 1;
  }
  node(bool type) { this->type = type; }
};
char ch[200];
map<string, node> mp;
string tmp;
int n;
string Void = "void";
int pos;
node gettype() {
  int idx = 0;
  while (ch[pos] == '&') {
    pos++;
    idx--;
  }
  string ts = "";
  while ((ch[pos] != '*') && (ch[pos] != ' ') && (ch[pos])) {
    ts += ch[pos++];
  }
  while (ch[pos] == '*') {
    pos++;
    idx++;
  }
  node TT;
  if (strcmp(Void.c_str(), ts.c_str()) != 0) {
    TT = mp[ts];
    TT.idx += idx;
    if (TT.idx < 0) {
      TT.type = 1;
    }
  } else
    TT = node(0, idx);
  return TT;
}
node ndtmp;
void print() {
  if (ndtmp.type == 1) {
    cout << "errtype" << endl;
  } else {
    cout << "void";
    for (int i = 0; i != ndtmp.idx; i++) {
      cout << '*';
    }
    cout << endl;
  }
}
int main() {
  cin >> n;
  cin.getline(ch, 200);
  for (int xx = 0; xx != n; xx++) {
    cin.getline(ch, 200);
    if (ch[4] == 'd') {
      pos = 8;
      ndtmp = gettype();
      pos++;
      tmp = "";
      while (ch[pos] != 0) {
        tmp += ch[pos++];
      }
      mp[tmp] = ndtmp;
    } else {
      pos = 7;
      ndtmp = gettype();
      print();
    }
  }
  return 0;
}
