#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a, bs, t;
  char c[50], P[50], A[50], B[50];
  map<string, int> m;
  map<string, bool> b;
  scanf("%d", &n);
  m["void"] = 0;
  m["errtype"] = -1;
  b["void"] = true;
  b["errtype"] = true;
  while (n--) {
    scanf("%s", c);
    if (strcmp(c, "typedef") == 0) {
      scanf("%s %s", P, B);
      a = bs = 0;
      t = strlen(P);
      for (int i = 0; i < t; i++) {
        if (P[i] == '&')
          bs--;
        else if (P[i] == '*')
          bs++;
        else
          A[a++] = P[i];
      }
      A[a] = '\0';
      string t1 = string(A), t2 = string(B);
      if (m[t1] == -1 || m[t1] + bs < 0 || b[t1] == false)
        m[t2] = -1;
      else
        m[t2] = m[t1] + bs;
      b[t2] = true;
    }
    if (strcmp(c, "typeof") == 0) {
      scanf("%s", P);
      a = bs = 0;
      t = strlen(P);
      for (int i = 0; i < t; i++) {
        if (P[i] == '&')
          bs--;
        else if (P[i] == '*')
          bs++;
        else
          A[a++] = P[i];
      }
      A[a] = '\0';
      string t = string(A);
      int p = m[t] + bs;
      if (m[t] == -1 || m[t] + bs < 0 || b[t] == false)
        printf("errtype\n");
      else {
        printf("void");
        for (int i = 0; i < p; i++) printf("*");
        printf("\n");
      }
    }
  }
}
