#include <bits/stdc++.h>
using namespace std;
const int MOD(1000000007);
const int INF((1 << 30) - 1);
const int MAXN();
map<string, int> d;
int main() {
  d["void"] = 0;
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    string a, b, c;
    cin >> a;
    if (a == "typedef") {
      cin >> b >> c;
      int k1 = 0, k2 = b.size() - 1, m = 0;
      while (k1 < b.size() && b[k1] == '&') k1++, m--;
      while (k2 >= 0 && b[k2] == '*') k2--, m++;
      string t = b.substr(k1, k2 - k1 + 1);
      if (!d.count(t) || d[t] == -1 || d[t] + m < 0)
        d[c] = -1;
      else
        d[c] = d[t] + m;
    } else {
      cin >> b;
      int k1 = 0, k2 = b.size() - 1, m = 0;
      while (k1 < b.size() && b[k1] == '&') k1++, m--;
      while (k2 >= 0 && b[k2] == '*') k2--, m++;
      string t = b.substr(k1, k2 - k1 + 1);
      if (!d.count(t) || d[t] == -1 || d[t] + m < 0)
        printf("errtype\n");
      else {
        printf("void");
        int l = d[t];
        for (int j = 0; j < l + m; j++) printf("*");
        printf("\n");
      }
    }
  }
}
