#include <bits/stdc++.h>
using namespace std;
map<string, string> S;
map<string, int> num;
bool check(string a) {}
void print(string b) {
  int po = 0, ne = 0, pos_head = 0, pos_tail = b.size() - 1;
  while (b[pos_head] == '&') pos_head++, po++;
  while (b[pos_tail] == '*') pos_tail--, ne++;
  string ts = b.substr(pos_head, pos_tail - pos_head + 1);
  if (S[ts] == "errtype" || S[ts] == "")
    cout << "errtype" << endl;
  else if (num[ts] + po - ne > 0) {
    int t = num[ts] + po - ne;
    if (S[ts] == "void")
      cout << "errtype" << endl;
    else {
      for (int j = 1; j <= t; j++) putchar('&');
      cout << S[ts] << endl;
    }
  } else if (num[ts] + po - ne <= 0) {
    cout << S[ts];
    int t = -(num[ts] + po - ne);
    for (int j = 1; j <= t; j++) putchar('*');
    puts("");
  }
}
int main() {
  string t;
  int n;
  scanf("%d", &n);
  S["void"] = "void";
  for (int i = 1; i <= n; i++) {
    string a, b, c;
    cin >> a;
    if (a == "typedef") {
      cin >> b >> c;
      int po = 0, ne = 0, pos_head = 0, pos_tail = b.size() - 1;
      while (b[pos_head] == '&') pos_head++, po++;
      while (b[pos_tail] == '*') pos_tail--, ne++;
      if (S[b.substr(pos_head, pos_tail - pos_head + 1)] != "") {
        S[c] = S[b.substr(pos_head, pos_tail - pos_head + 1)];
        num[c] = (num[b.substr(pos_head, pos_tail - pos_head + 1)] + po - ne);
        if (S[c] == "void" && num[c] > 0) S[c] = "errtype";
      } else
        S[c] = "errtype";
    } else {
      cin >> b;
      print(b);
    }
  }
  return 0;
}
