#include <bits/stdc++.h>
using namespace std;
const string s1 = "typeof";
const string s2 = "typedef";
map<string, int> mp;
pair<string, int> parse(string s) {
  int cnt = 0;
  int l = s.length();
  for (int i = l - 1; i >= 0; --i) {
    if (s[i] == '*')
      cnt++;
    else
      break;
  }
  int i = 0;
  int cnt2 = 0;
  while (i < l && s[i] == '&') cnt2++, i++;
  string ss;
  for (; i < l; ++i) {
    if (s[i] == '*') break;
    ss += s[i];
  }
  return make_pair(ss, cnt - cnt2);
}
int main() {
  int n;
  cin >> n;
  mp["void"] = 0;
  while (n--) {
    string s;
    cin >> s;
    if (s == s2) {
      cin >> s;
      string s1;
      cin >> s1;
      pair<string, int> p = parse(s);
      if (mp.find(p.first) == mp.end() || mp[p.first] < 0) {
        mp[s1] = -1;
      } else {
        int cnt = mp[p.first] + p.second;
        if (cnt < 0)
          mp[s1] = -1;
        else
          mp[s1] = cnt;
      }
    } else {
      cin >> s;
      pair<string, int> p = parse(s);
      if (mp.find(p.first) == mp.end() || mp[p.first] < 0) {
        cout << "errtype" << endl;
      } else {
        int cnt = mp[p.first] + p.second;
        if (cnt < 0) {
          cout << "errtype" << endl;
        } else {
          cout << "void";
          for (int j = 0; j < cnt; ++j) cout << "*";
          cout << endl;
        }
      }
    }
  }
  return 0;
}
