#include <bits/stdc++.h>
using namespace std;
void println() { cout << '\n'; }
template <typename Head, typename... Tail>
void println(Head H, Tail... T) {
  cout << " " << H;
  println(T...);
}
void debug_out() { cerr << '\n'; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << H;
  debug_out(T...);
}
const int INF = 1e9;
const long long MOD = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  map<string, int> types;
  types["void"] = 0;
  types["errtype"] = -1;
  while (n--) {
    string op, a, b;
    cin >> op >> a;
    int amps = 0, stars = 0;
    string id = "";
    for (char c : a) {
      switch (c) {
        case '&':
          amps++;
          break;
        case '*':
          stars++;
          break;
        default:
          id += c;
      }
    }
    int inc = stars - amps;
    if (op == "typedef") {
      cin >> b;
      if (!types.count(id) || types[id] < 0 || inc + types[id] < 0) {
        types[b] = -1;
        continue;
      }
      types[b] = types[id] + inc;
    } else {
      if (!types.count(id) || types[id] < 0 || inc + types[id] < 0) {
        cout << "errtype\n";
        continue;
      }
      cout << "void";
      for (int i = int(1); i <= int(types[id] + inc); i++) cout << "*";
      cout << '\n';
    }
  }
  return 0;
}
