#include <bits/stdc++.h>
using namespace std;
struct vartype {
  string orig;
  int ast, amp;
} typedef vartype;
char command[30];
char tp[100];
map<string, vartype> mp;
void init() {
  vartype nv;
  string word = "void";
  nv.orig = word;
  nv.ast = 0;
  nv.amp = 0;
  mp[word] = nv;
  word = "errtype";
  nv.orig = word;
  nv.ast = 0;
  nv.amp = 0;
  mp[word] = nv;
}
void expand(string vl) {
  if (vl == "void" || vl == "errtype" || mp.find(vl) == mp.end()) return;
  vartype vt = mp[vl];
  expand(vt.orig);
  vartype ovt = mp[vt.orig];
  vt.orig = ovt.orig;
  vt.ast += ovt.ast;
  vt.amp += ovt.amp;
  if (vt.ast >= vt.amp) {
    vt.ast -= vt.amp;
    vt.amp = 0;
  } else {
    vt.amp -= vt.ast;
    vt.ast = 0;
  }
  if (vt.amp > 0) {
    vt.amp = 0;
    vt.orig = "errtype";
  }
  if (vt.orig == "errtype") {
    vt.ast = 0;
    vt.amp = 0;
  }
  mp[vl] = vt;
}
void print(string cur, int amp, int ast) {
  if (mp.find(cur) == mp.end()) {
    printf("errtype\n");
    return;
  }
  vartype vt = mp[cur];
  int i;
  vt.amp += amp;
  vt.ast += ast;
  if (vt.ast >= vt.amp) {
    vt.ast -= vt.amp;
    vt.amp = 0;
  } else {
    vt.amp -= vt.ast;
    vt.ast = 0;
  }
  if (vt.amp > 0) {
    vt.amp = 0;
    vt.orig = "errtype";
  }
  if (vt.orig == "errtype") {
    vt.ast = 0;
    vt.amp = 0;
  }
  for (i = 0; i < vt.amp; i++) printf("&");
  printf("%s", vt.orig.c_str());
  for (i = 0; i < vt.ast; i++) printf("*");
  printf("\n");
}
int main() {
  init();
  int n, i;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf(" %s", command);
    if (command[4] == 'd') {
      scanf(" %s", tp);
      string word = "";
      int amp = 0, ast = 0, len = 0;
      while (tp[amp] == '&') amp++;
      while (tp[amp + len] != '*' && tp[amp + len] != '\0')
        word += tp[amp + (len++)];
      while (tp[amp + len + ast] == '*' && tp[amp + len + ast] != '\0') ast++;
      if (ast >= amp) {
        ast -= amp;
        amp = 0;
      } else {
        amp -= ast;
        ast = 0;
      }
      vartype nv;
      nv.orig = word;
      nv.ast = ast;
      nv.amp = amp;
      scanf(" %s", tp);
      string cur = tp;
      if (mp.find(word) == mp.end()) {
        nv.orig = "errtype";
        nv.ast = 0;
        nv.amp = 0;
      } else {
        if (cur == word) {
          nv.orig = mp[cur].orig;
          nv.ast = ast + mp[cur].ast;
          nv.amp = amp + mp[cur].amp;
        }
      }
      mp[cur] = nv;
    } else {
      scanf(" %s", tp);
      string word = "";
      int amp = 0, ast = 0, len = 0;
      while (tp[amp] == '&') amp++;
      while (tp[amp + len] != '*' && tp[amp + len] != '\0')
        word += tp[amp + (len++)];
      while (tp[amp + len + ast] == '*' && tp[amp + len + ast] != '\0') ast++;
      expand(word);
      print(word, amp, ast);
    }
  }
  return 0;
}
