#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  map<string, int> m;
  string a, b, c, base;
  m["void"] = 0;
  m["errtype"] = -1;
  cin >> n;
  while (n--) {
    cin >> a >> b;
    int f = b.find_first_not_of('&');
    int l = b.find_last_not_of('*');
    base = b.substr(f, l - f + 1);
    int lvl;
    if (m.count(base) == 0 || m[base] < 0)
      lvl = -1;
    else
      lvl = m[base] - f + b.size() - l - 1;
    if (a[4] == 'o') {
      cout << (lvl < 0 ? "errtype" : "void");
      for (int j = 0; j < lvl; ++j) cout << "*";
      cout << endl;
    } else {
      cin >> c;
      m[c] = lvl;
    }
  }
}
