#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
const long long inf = 1e17 + 7;
string first(long long num) {
  string second = "";
  for (long long i = 0; i < num; i++) second += '*';
  return second;
}
signed main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  cout.precision(10);
  map<string, long long> a;
  a["void"] = 0;
  long long n;
  cin >> n;
  while (n--) {
    string type, st, to;
    cin >> type >> st;
    long long l = st.find_first_not_of("&");
    long long r = st.find_last_not_of("*");
    long long cnt = st.size() - r - 1 - l;
    string temp = st.substr(l, r - l + 1);
    if (type == "typeof") {
      if (a.find(temp) == a.end() || a[temp] + min(0ll, cnt) < 0)
        cout << "errtype" << endl;
      else
        cout << "void" << first(a[temp] + cnt) << endl;
    } else {
      cin >> to;
      if (a.find(temp) == a.end() || a[temp] < 0)
        a[to] = -1;
      else
        a[to] = a[temp] + cnt;
    }
  }
}
