#include <bits/stdc++.h>
using namespace std;
int main() {
  string a, b, c;
  map<string, int> mp;
  int n;
  cin >> n;
  mp["void"] = 0;
  for (int i = 0; i < n; i++) {
    cin >> a;
    if (a == "typedef") {
      cin >> b >> c;
      int x = 0;
      while (b[0] == '&') {
        x++;
        b.erase(0, 1);
      }
      int y = 0;
      while (b[b.length() - 1] == '*') {
        y++;
        b.erase(b.length() - 1, 1);
      }
      if (mp.find(b) == mp.end() || mp[b] < 0)
        mp[c] = -1;
      else if (mp[b] + y - x < 0)
        mp[c] = -1;
      else
        mp[c] = mp[b] + y - x;
    } else {
      cin >> b;
      int x = 0;
      while (b[0] == '&') {
        x++;
        b.erase(0, 1);
      }
      int y = 0;
      while (b[b.length() - 1] == '*') {
        y++;
        b.erase(b.length() - 1, 1);
      }
      if (mp.find(b) == mp.end() || mp[b] < 0 || mp[b] + y - x < 0)
        cout << "errtype" << endl;
      else {
        int r = mp[b] + y - x;
        cout << "void";
        for (int j = 0; j < r; j++) cout << "*";
        cout << endl;
      }
    }
  }
  return 0;
}
