#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
const long long int inf = 1e18;
long long int n;
string s1, a, b;
map<string, long long int> ma;
long long int solve(string s) {
  long long int x = 0, cum1 = 0, cum2 = 0, ind1 = 0, ind2 = s.size() - 1;
  for (int i = 0; i < ind2 + 1; i++) {
    if (s[i] != '&') {
      break;
    }
    cum1++;
    ind1++;
  }
  for (int i = s.size() - 1; i > -1; i--) {
    if (s[i] != '*') {
      break;
    }
    cum2++;
    ind2--;
  }
  string t = s.substr(ind1, ind2 - ind1 + 1);
  if (!ma.count(t)) {
    return -1;
  }
  x = ma[t];
  if (x == -1) {
    return -1;
  }
  x += cum2 - cum1;
  if (x < 0) {
    return -1;
  }
  return x;
}
int main(void) {
  ma["void"] = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s1 >> a;
    if (s1 == "typedef") {
      cin >> b;
      ma[b] = solve(a);
    } else {
      long long int x = solve(a);
      if (x == -1) {
        cout << "errtype" << endl;
      } else {
        cout << "void";
        for (int i = 0; i < x; i++) {
          cout << "*";
        }
        cout << endl;
      }
    }
  }
}
