#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-8;
map<string, int> m;
set<string> ss;
int main() {
  m["void"] = 0;
  ss.insert("void");
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    if (s == "typeof") {
      cin >> s;
      int x = 0;
      while (s[s.length() - 1] == '*') {
        s.erase(s.begin() + s.length() - 1);
        x++;
      }
      while (s[0] == '&') {
        s.erase(s.begin());
        x--;
      }
      if (ss.find(s) == ss.end())
        cout << "errtype" << endl;
      else {
        x += m[s];
        if (x < 0 || m[s] < 0)
          cout << "errtype" << endl;
        else {
          cout << "void";
          for (; x; x--) cout << "*";
          cout << endl;
        }
      }
    } else {
      string s1;
      cin >> s >> s1;
      ss.insert(s1);
      int x = 0;
      while (s[s.length() - 1] == '*') {
        s.erase(s.begin() + s.length() - 1);
        x++;
      }
      while (s[0] == '&') {
        s.erase(s.begin());
        x--;
      }
      if (ss.find(s) == ss.end()) {
        m[s1] = -1;
        continue;
      }
      if (m[s] < 0) {
        m[s1] = -1;
        continue;
      }
      x += m[s];
      if (x < 0) {
        m[s1] = -1;
        continue;
      }
      m[s1] = x;
    }
  }
}
