#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  map<string, int> mp;
  map<string, bool> ok, er;
  ok["void"] = 1;
  mp["void"] = 0;
  er["errtype"] = 1;
  while (n--) {
    string s, a, b;
    cin >> s >> a;
    int cnt = 0;
    string tmp;
    for (int i = 0; i < (int)a.size(); i++) {
      if (a[i] == '&')
        cnt--;
      else if (a[i] == '*')
        cnt++;
      else
        tmp += a[i];
    }
    if (s[4] == 'd') {
      cin >> b;
      int tot = cnt + mp[tmp];
      if (!ok[tmp] || tot < 0 || er[tmp]) {
        er[b] = 1;
      } else {
        ok[b] = 1, mp[b] = tot, er[b] = 0;
      }
    } else {
      int tot = mp[tmp] + cnt;
      if (er[tmp] || tot < 0 || !ok[tmp]) {
        cout << "errtype\n";
      } else {
        cout << "void";
        while (tot--) cout << '*';
        cout << '\n';
      }
    }
  }
  return 0;
}
