#include <bits/stdc++.h>
using namespace std;
int main() {
  int q, pointer;
  scanf("%d", &q);
  map<string, int> type;
  char op[10], v[22], name[22];
  string op_str, v_str, name_str;
  type.insert(make_pair("void", 0));
  while (q--) {
    scanf("%s %s", op, v);
    op_str = op;
    v_str = v;
    int amp = 0, ask = 0, pointer = 0, len = 0, k = 0;
    for (int i = 0; i < v_str.length() && v_str[i] == '&'; i++) amp++;
    k = amp;
    for (int i = amp; i < v_str.length() && v_str[i] != '*'; i++) {
      len++;
      k++;
    }
    string aux = v_str.substr(amp, len);
    if (type.find(aux) == type.end())
      pointer = -1;
    else
      pointer = type[aux];
    for (int i = k; i < v_str.length(); i++) ask++;
    if (pointer < 0 || pointer + ask - amp < 0) {
      if (op_str == "typeof")
        printf("errtype\n");
      else {
        scanf("%s", name);
        name_str = name;
        type[name_str] = -1;
      }
    } else {
      if (op_str == "typeof") {
        printf("void");
        for (int i = 0; i < pointer + ask - amp; i++) printf("*");
        printf("\n");
      } else {
        scanf("%s", name);
        name_str = name;
        type[name_str] = pointer + ask - amp;
      }
    }
  }
  return 0;
}
