#include <bits/stdc++.h>
using namespace std;
const int dr[] = {0, -1, 0, 1, -1, 1, 1, -1};
const int dc[] = {1, 0, -1, 0, 1, 1, -1, -1};
const double eps = 1e-9;
template <class T>
void print(const vector<T> &v) {
  ostringstream os;
  for (int i = 0; i < (int)v.size(); ++i) {
    if (i) os << ' ';
    os << v[i];
  }
  cout << os.str() << endl;
}
template <class T>
int sz(const T &c) {
  return (int)c.size();
}
template <class T>
void srt(T &c) {
  sort(c.begin(), c.end());
}
template <class T>
void checkmin(T &a, T b) {
  if (b < a) a = b;
}
template <class T>
void checkmax(T &a, T b) {
  if (b > a) a = b;
}
template <class T>
T sqr(T x) {
  return x * x;
}
template <class T, class U>
T cast(U x) {
  ostringstream os;
  os << x;
  T res;
  istringstream is(os.str());
  is >> res;
  return res;
}
template <class T>
vector<T> split(string s, string x = " ") {
  vector<T> res;
  for (int i = 0; i < s.size(); i++) {
    string a;
    while (i < (int)s.size() && x.find(s[i]) == string::npos) a += s[i++];
    if (!a.empty()) res.push_back(cast<T>(a));
  }
  return res;
}
template <class T>
bool inside(T r, T c, T R, T C) {
  return r >= 0 && r < R && c >= 0 && c < C;
}
int get_amp(string s) { return count(s.begin(), s.end(), '&'); }
int get_star(string s) { return count(s.begin(), s.end(), '*'); }
string clean(string s) {
  while (s[sz(s) - 1] == '*') s.erase(sz(s) - 1);
  while (s[0] == '&') s.erase(0, 1);
  return s;
}
int main(int argc, char *argv[]) {
  int n;
  cin >> n;
  string s;
  getline(cin, s);
  map<string, string> t;
  t["void"] = "void";
  t["errtype"] = "errtype";
  for (int i(0), _n(n); i < _n; ++i) {
    getline(cin, s);
    vector<string> a = split<string>(s);
    string type = a[1];
    string clean_type = clean(type);
    string type2 = "errtype";
    if (t.count(clean_type)) type2 = t[clean_type];
    if (type2 != "errtype")
      type2 = string(get_amp(type), '&') + t[clean_type] +
              string(get_star(type), '*');
    while (type2[0] == '&' && type2[sz(type2) - 1] == '*')
      type2.erase(sz(type2) - 1, 1), type2.erase(0, 1);
    if (type2[0] == '&') type2 = "errtype";
    if (a[0] == "typeof")
      cout << type2 << endl;
    else
      t[a[2]] = type2;
  }
  return 0;
}
