#include <bits/stdc++.h>
using namespace std;
struct type {
  bool isErr;
  int asteriksNum;
  type(int asteriksNum = 0) : isErr(0), asteriksNum(asteriksNum) {}
};
int main(int argc, char** argv) {
  if (argc > 1) freopen(argv[1], "r", stdin);
  int n;
  cin >> n;
  map<string, type> types;
  types["void"] = type();
  (types["errtype"] = type()).isErr = true;
  string a, b, c;
  for (int i = 0; i < (n); ++i) {
    cin >> a >> b;
    int num = 0;
    int j = 0;
    while (j < ((int)((b).size())) && b[j] == '&') --num, ++j;
    string name = "";
    while (j < ((int)((b).size())) && b[j] != '*') name += b[j++];
    num += ((int)((b).size())) - j;
    bool exists = types.find(name) != types.end();
    if (exists) num += types[name].asteriksNum;
    if (a == "typedef") {
      cin >> c;
      if (!exists || types[name].isErr) {
        types[c] = types["errtype"];
        continue;
      }
      if (num < 0) {
        types[c] = types["errtype"];
      } else {
        types[c] = type(num);
      }
    } else {
      if (num < 0 || !exists || types[name].isErr)
        printf("errtype\n");
      else {
        printf("void");
        for (int i = 0; i < (num); ++i) printf("*");
        printf("\n");
      }
    }
  }
  return 0;
}
