#include <bits/stdc++.h>
using namespace std;
map<string, int> mp;
map<string, bool> mps;
int n;
string s;
string work(string ss) {
  int t, tt;
  for (int i = 0; i < ss.size(); i++) {
    if (ss[i] != '&') {
      t = i;
      break;
    }
  }
  for (int i = ss.size() - 1; i >= 0; i--) {
    if (ss[i] != '*') {
      tt = i;
      break;
    }
  }
  return ss.substr(t, tt - t + 1);
}
int main() {
  cin >> n;
  mps["void"] = 1;
  mp["void"] = 0;
  for (int i = 0; i < n; i++) {
    cin >> s;
    if (s == "typedef") {
      string a, b;
      cin >> a >> b;
      int xi = count(a.begin(), a.end(), '*');
      int yi = count(a.begin(), a.end(), '&');
      string st = work(a);
      if (!mps[st] || mp[st] < 0)
        mp[b] = -1;
      else if (yi > xi + mp[st])
        mp[b] = -1;
      else
        mp[b] = xi + mp[st] - yi;
      mps[b] = 1;
    } else {
      string ss;
      cin >> ss;
      int xi = count(ss.begin(), ss.end(), '*');
      int yi = count(ss.begin(), ss.end(), '&');
      string st = work(ss);
      int t = mp[st] + xi - yi;
      if (!mps[st] || t < 0 || mp[st] < 0)
        cout << "errtype\n";
      else {
        cout << "void";
        for (int i = 0; i < t; i++) cout << "*";
        cout << "\n";
      }
    }
  }
  return 0;
}
