#include <bits/stdc++.h>
const int N = 100010;
const int inf = 0x3f3f3f3f;
using namespace std;
map<string, int> A, B;
string y;
int solve(string x) {
  y = "";
  int sz = x.size();
  int a = 0, b = 0;
  for (int i = 0; i < sz; i++) {
    if (x[i] == '*')
      a++;
    else if (x[i] == '&')
      b++;
    else
      y += x[i];
  }
  if (B[y] == 0 || A[y] == inf || (A[y] + a - b) < 0) return inf;
  return A[y] + a - b;
}
int main() {
  int n;
  cin >> n;
  A["void"] = 0;
  B["void"] = 1;
  for (int i = 0; i < n; i++) {
    string a, b, c;
    cin >> a >> b;
    if (a == "typedef") {
      cin >> c;
      A[c] = solve(b);
      B[c] = B[y];
    } else {
      A[b] = solve(b);
      if (A[b] == inf)
        puts("errtype");
      else {
        printf("void");
        for (int j = 0; j < A[b]; j++) printf("*");
        puts("");
      }
    }
  }
  return 0;
}
