#include <bits/stdc++.h>
using namespace std;
long long power(long long x, long long y, long long p) {
  long long res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
const int N = 1e5 + 7;
const int xinc[] = {0, 0, 1, -1};
const int yinc[] = {1, -1, 0, 0};
const long double PI = acos(-1.0);
const double EPS = 1e-9;
struct type {
  bool valid;
  int stars;
  type(bool val = false, int st = 0) : valid(val), stars(st) {}
};
map<string, type> m;
int n;
string s;
string op, t1, t2;
void solve() {
  cin >> n;
  m["void"] = type(true, 0);
  getline(cin, s);
  for (int i = 0; i < n; i++) {
    getline(cin, s);
    stringstream ss;
    ss << s;
    ss >> op;
    if (op == "typedef") {
      ss >> t1 >> t2;
      int andcnt = 0, stcnt = 0;
      int i = 0;
      string tt;
      while (t1[i] == '&') andcnt++, i++;
      while (i < t1.size() && t1[i] != '*') tt += t1.substr(i++, 1);
      while (i < t1.size()) stcnt++, i++;
      if (!m[tt].valid)
        m[t2] = type(false, 0);
      else {
        stcnt += m[tt].stars;
        if (andcnt > stcnt)
          m[t2] = type(false, 0);
        else
          m[t2] = type(true, stcnt - andcnt);
      }
    } else {
      ss >> t1;
      int andcnt = 0, stcnt = 0;
      int i = 0;
      string tt;
      while (t1[i] == '&') andcnt++, i++;
      while (i < t1.size() && t1[i] != '*') tt += t1.substr(i++, 1);
      while (i < t1.size()) stcnt++, i++;
      if (!m[tt].valid)
        cout << "errtype" << '\n';
      else {
        stcnt += m[tt].stars;
        if (andcnt > stcnt)
          cout << "errtype" << '\n';
        else {
          cout << "void";
          for (int i = 0; i < stcnt - andcnt; i++) cout << "*";
          cout << '\n';
        }
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  t = 1;
  while (t--) solve();
  return 0;
}
