#include <bits/stdc++.h>
using namespace std;
const int OO = (int)1000;
const double EPS = 1e-9;
struct var {
  string type;
  int ampersand, pointer;
};
map<string, var> m;
int n;
string op, a, b;
int removeChar(string &s, char c) {
  int ret = 0;
  for (int i = 0; i < (int)s.size(); i++)
    if (s[i] == c) {
      s.erase(i, 1);
      i--;
      ret++;
    }
  return ret;
}
int main() {
  m["void"] = var{"void", 0, 0};
  cin >> n;
  for (int l = 0; l < n; l++) {
    cin >> op >> a;
    int amp = removeChar(a, '&'), po = removeChar(a, '*');
    if (op == "typedef") {
      cin >> b;
      if (m.find(a) != m.end()) {
        var par = m[a];
        if (par.pointer - par.ampersand < 0)
          m[b] = var{"errtype", OO, 0};
        else
          m[b] = var{par.type, par.ampersand + amp, par.pointer + po};
      } else
        m[b] = var{"errtype", OO, 0};
    } else if (op == "typeof") {
      if (m.find(a) != m.end()) {
        var x = m[a];
        int diff = x.pointer + po - x.ampersand - amp;
        if (x.pointer - x.ampersand < 0) diff = -1;
        if (diff < 0)
          cout << "errtype" << endl;
        else {
          cout << "void";
          while (diff--) cout << "*";
          cout << endl;
        }
      } else {
        cout << "errtype" << endl;
      }
    }
  }
  return 0;
}
