#include <bits/stdc++.h>
using namespace std;
struct Type {
  bool iserror;
  int npt;
};
map<string, Type> m;
Type parseType(string b) {
  Type returnType;
  int amps = 0;
  int stars = 0;
  for (int j = 0; j < b.length(); ++j) {
    if (b[j] == '*')
      stars++;
    else if (b[j] == '&')
      amps++;
  }
  b = b.substr(amps, b.length() - stars - amps);
  if (m.find(b) == m.end()) {
    returnType.iserror = true;
  } else {
    if (m[b].iserror) {
      returnType.iserror = true;
    } else if (stars - amps + m[b].npt < 0) {
      returnType.iserror = true;
    } else {
      returnType.iserror = false;
      returnType.npt = stars - amps + m[b].npt;
    }
  }
  return returnType;
}
int main() {
  int n;
  cin >> n;
  m["void"].iserror = false;
  m["void"].npt = 0;
  for (int i = 0; i < n; ++i) {
    string a, b, c;
    cin >> a;
    if (a == "typedef") {
      cin >> b >> c;
      m[c] = parseType(b);
    } else {
      cin >> b;
      Type t = parseType(b);
      if (t.iserror) {
        cout << "errtype" << endl;
      } else {
        cout << "void";
        for (int i = 0; i < t.npt; ++i) cout << "*";
        cout << endl;
      }
    }
  }
}
