#include <bits/stdc++.h>
using namespace std;
map<string, string> ma;
int main() {
  long long n, i, ans1, ans2;
  string a, b, s;
  cin >> n;
  ma["void"] = "void";
  ma["errtype"] = "errtype";
  for (int j = 1; j <= n; j++) {
    cin >> s;
    if (s == "typedef") {
      ans1 = 0, ans2 = 0;
      cin >> a >> b;
      for (i = 0; i < a.size(); i++)
        ans1 = ans1 + (a[i] == '&'), ans2 = ans2 + (a[i] == '*');
      s = "";
      for (i = 0; i < a.size(); i++)
        if (a[i] != '*' && a[i] != '&') s = s + a[i];
      a = ma[s];
      if (a == "") continue;
      for (i = 0; i < a.size(); i++)
        ans1 = ans1 + (a[i] == '&'), ans2 = ans2 + (a[i] == '*');
      s = "";
      for (i = 0; i < a.size(); i++)
        if (a[i] != '*' && a[i] != '&') s = s + a[i];
      if (ans1 > ans2)
        ma[b] = "errtype";
      else {
        for (i = 1; i <= ans2 - ans1; i++) s = s + '*';
        ma[b] = s;
      }
    } else {
      ans1 = 0, ans2 = 0;
      cin >> a;
      for (i = 0; i < a.size(); i++)
        ans1 = ans1 + (a[i] == '&'), ans2 = ans2 + (a[i] == '*');
      string s = "";
      for (i = 0; i < a.size(); i++)
        if (a[i] != '*' && a[i] != '&') s = s + a[i];
      a = ma[s];
      if (a.size() == 0) {
        cout << "errtype\n";
        continue;
      }
      for (i = 0; i < a.size(); i++)
        ans1 = ans1 + (a[i] == '&'), ans2 = ans2 + (a[i] == '*');
      s = "";
      for (i = 0; i < a.size(); i++)
        if (a[i] != '*' && a[i] != '&') s = s + a[i];
      if (ans1 > ans2 || s == "errtype")
        cout << "errtype\n";
      else {
        cout << s;
        for (i = 1; i <= ans2 - ans1; i++) cout << "*";
        cout << '\n';
      }
    }
  }
}
