#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
map<string, int> mp;
void print(int a) {
  if (a == -1) {
    cout << "errtype" << endl;
  } else {
    cout << "void";
    for (int i = 0; i < a; i++) {
      cout << '*';
    }
    cout << endl;
  }
}
int gettype(string str) {
  int i = 0;
  while (str[i] == '&') {
    i++;
  }
  int j = str.size() - 1;
  while (str[j] == '*') {
    j--;
  }
  string name = "";
  for (int k = i; k <= j; k++) {
    name += str[k];
  }
  j = str.size() - j - 1;
  if (mp.find(name) == mp.end()) {
    return -1;
  } else {
    int origin = mp[name];
    if (origin == -1) {
      return -1;
    } else if (origin + j - i < 0) {
      return -1;
    } else {
      return origin + j - i;
    }
  }
}
int main() {
  mp["void"] = 0;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string tmp;
    cin >> tmp;
    if (tmp == "typedef") {
      string a, b;
      cin >> a >> b;
      mp[b] = gettype(a);
    } else {
      string a;
      cin >> a;
      print(gettype(a));
    }
  }
  return 0;
}
