#include <bits/stdc++.h>
using namespace std;
map<string, string> m;
int n;
char op[1000];
char s1[1000], s2[1000];
string a, b;
void yinshe() {
  int zzl1 = 0;
  int zzl2 = 0;
  int i, j;
  for (i = 0; i < strlen(s1); i++) {
    if (s1[i] == '&')
      zzl1++;
    else
      break;
  }
  for (j = strlen(s1) - 1; j >= 0; j--) {
    if (s1[j] == '*')
      zzl2++;
    else
      break;
  }
  string zhongjian = "";
  for (int k = i; k <= j; k++) zhongjian += s1[k];
  string temp = s2;
  if (m.find(zhongjian) == m.end()) {
    if (zzl1 > zzl2)
      zhongjian = "errtype";
    else if (zhongjian.compare("void") != 0)
      zhongjian = "errtype";
    else
      for (int i = 1; i <= zzl2 - zzl1; i++) zhongjian += '*';
  } else {
    zhongjian = m[zhongjian];
    if (zhongjian.compare("errtype") == 0) {
    } else {
      for (i = zhongjian.length() - 1; i >= 0; i--)
        if (zhongjian[i] == '*')
          zzl2++;
        else
          break;
      string tt = "";
      for (j = 0; j <= i; j++) {
        tt += zhongjian[j];
      }
      zhongjian = tt;
      if (zzl1 > zzl2)
        zhongjian = "errtype";
      else
        for (int i = 1; i <= zzl2 - zzl1; i++) zhongjian += '*';
    }
  }
  m[temp] = zhongjian;
}
void query() {
  int i, j;
  int zzl1 = 0;
  int zzl2 = 0;
  for (i = 0; i < strlen(s1); i++) {
    if (s1[i] == '&')
      zzl1++;
    else
      break;
  }
  for (j = strlen(s1) - 1; j >= 0; j--) {
    if (s1[j] == '*')
      zzl2++;
    else
      break;
  }
  string zhongjian = "";
  for (int k = i; k <= j; k++) zhongjian += s1[k];
  if (m.find(zhongjian) == m.end()) {
    if (zhongjian.compare("void") == 0) {
      if (zzl1 > zzl2)
        zhongjian = "errtype";
      else
        for (int i = 1; i <= zzl2 - zzl1; i++) zhongjian += '*';
    } else
      zhongjian = "errtype";
    cout << zhongjian << endl;
  } else {
    string temp = m[zhongjian];
    if (temp.compare("errtype") == 0) {
      cout << temp << endl;
      return;
    }
    zhongjian = m[zhongjian];
    for (i = zhongjian.length() - 1; i >= 0; i--)
      if (zhongjian[i] == '*')
        zzl2++;
      else
        break;
    string tt = "";
    for (j = 0; j <= i; j++) {
      tt += zhongjian[j];
    }
    zhongjian = tt;
    if (zzl1 > zzl2)
      zhongjian = "errtype";
    else
      for (int i = 1; i <= zzl2 - zzl1; i++) zhongjian += '*';
    cout << zhongjian << endl;
  }
}
void solve() {
  scanf("%s", op);
  if (strcmp(op, "typedef") == 0) {
    scanf("%s%s", s1, s2);
    yinshe();
  } else {
    scanf("%s", s1);
    query();
  }
}
int main() {
  while (scanf("%d", &n) != EOF) {
    m.clear();
    for (int i = 0; i < n; i++) solve();
  }
}
