#include <bits/stdc++.h>
using namespace std;
int n;
string op, a, b;
map<string, int> db;
int main() {
  db["void"] = 0;
  db["errtype"] = -1e9;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    cin >> op >> a;
    if (op == "typedef") cin >> b;
    int amp = 0, ast = a.length() - 1;
    while (a[amp] == '&') amp++;
    while (a[ast] == '*') ast--;
    string newa = a.substr(amp, ast - amp + 1);
    int bal;
    if (db.find(newa) == db.end())
      bal = -1e9;
    else
      bal = a.length() - ast - 1 + db[newa] - amp;
    if (newa == "errtype") bal = -1e9;
    if (op == "typedef") {
      db[b] = (bal < 0 ? -1e9 : bal);
    } else {
      if (bal < 0)
        puts("errtype");
      else {
        printf("void");
        for (int j = 0; j < bal; j++) putchar('*');
        putchar('\n');
      };
    };
  };
  return 0;
}
