#include <bits/stdc++.h>
using namespace std;
map<string, string> op;
string fun(string second) {
  string ans = "";
  for (int i = 0; i < second.size(); i++) {
    if (second[i] != '*' && second[i] != '&') ans += second[i];
  }
  return ans;
}
void solve(string a, string b) {
  int amp = 0, ast = 0;
  string parent = fun(a);
  if (parent == "errtype") {
    op[b] = "errtype";
    return;
  }
  if (op.find(parent) == op.end()) {
    op[b] = "errtype";
    return;
  }
  for (int i = 0; i < a.size(); i++) {
    amp += a[i] == '&';
    ast += a[i] == '*';
  }
  string parentType = op[parent];
  if (parentType == "errtype") {
    op[b] = parentType;
    return;
  }
  for (int i = 0; i < parentType.size(); i++) {
    amp += parentType[i] == '&';
    ast += parentType[i] == '*';
  }
  if (amp - ast > 0) {
    op[b] = "errtype";
    return;
  }
  string alt = fun(parentType);
  for (int i = 0; i < ast - amp; i++) alt += '*';
  op[b] = alt;
}
string Type(string a) {
  string alt = fun(a);
  if (op.find(alt) == op.end()) {
    return "errtype";
  }
  string t = op[alt];
  string ans = fun(t);
  if (t == "errtype") {
    return t;
  }
  int amp = 0, ast = 0;
  for (int i = 0; i < t.size(); i++) ast += t[i] == '*';
  for (int i = 0; i < a.size(); i++) {
    amp += a[i] == '&';
    ast += a[i] == '*';
  }
  if (amp - ast > 0) {
    return "errtype";
  }
  for (int i = 0; i < ast - amp; i++) ans += '*';
  return ans;
}
int main() {
  op["void"] = "void";
  op["errtype"] = "errtype";
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    string type;
    cin >> type;
    if (type == "typedef") {
      string a, b;
      cin >> a >> b;
      solve(a, b);
    } else {
      string var;
      cin >> var;
      cout << Type(var) << "\n";
    }
  }
  return 0;
}
