#include <bits/stdc++.h>
using namespace std;
map<string, int> A;
string s;
int main() {
  A["void"] = 100;
  A["errtype"] = 0;
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> s;
    if (s[4] == 'd') {
      string a, b;
      cin >> a >> b;
      int l = a.length();
      int p = 0, q = 0;
      for (int j = 0; j < l; ++j)
        if (a[j] == '&')
          ++p;
        else if (a[j] == '*')
          ++q;
      a = a.substr(p, l - p - q);
      q -= p;
      if (A[a] + q < 100)
        A[b] = 0;
      else
        A[b] = A[a] + q;
    } else {
      string a;
      cin >> a;
      int p = 0, q = 0;
      int l = a.length();
      for (int j = 0; j < l; ++j)
        if (a[j] == '&')
          ++p;
        else if (a[j] == '*')
          ++q;
      a = a.substr(p, l - p - q);
      q -= p;
      if (A[a] + q < 100)
        puts("errtype");
      else {
        printf("void");
        int t = A[a] + q;
        for (int j = 100; j < t; ++j) printf("*");
        puts("");
      }
    }
  }
  return 0;
}
