#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const double eps = 1e-9;
int n;
map<string, int> key;
int err = -1;
int main() {
  string op, a, b;
  while (cin >> n) {
    key.clear();
    key["void"] = 0;
    for (int k = 0; k < n; ++k) {
      cin >> op >> a;
      int l = a.length(), x = 0, y = 0;
      for (int i = 0; i < l; ++i) {
        if (a[i] == '&') {
          ++x;
        } else
          break;
      }
      for (int i = l - 1; i >= 0; --i) {
        if (a[i] == '*') {
          ++y;
        } else
          break;
      }
      a = a.substr(x, l - x - y);
      if (op == "typedef") {
        cin >> b;
        if (key.find(a) != key.end()) {
          if (key[a] == err) {
            key[b] = err;
          } else {
            y = y - x + key[a];
            if (y < 0)
              key[b] = err;
            else
              key[b] = y;
          }
        } else {
          key[b] = err;
        }
      } else {
        if (key.find(a) == key.end() || key[a] == err || key[a] + y < x) {
          puts("errtype");
        } else {
          printf("void");
          for (int i = key[a] + y - x; i; --i) {
            putchar('*');
          }
          putchar(10);
        }
      }
    }
  }
  return 0;
}
