#include <bits/stdc++.h>
using namespace std;
map<string, int> M;
string s1, s2, s3, s;
int N;
int main() {
  int i, j;
  cin >> N;
  M["void"] = 1;
  M["errtype"] = -1;
  for (i = 1; i <= N; i++) {
    cin >> s1;
    if (s1 == "typeof") {
      cin >> s2;
      s = "";
      int c1 = 0;
      for (j = 1; j <= s2.length(); j++)
        if (s2[j - 1] == '&')
          c1--;
        else if (s2[j - 1] == '*')
          c1++;
        else
          s = s + s2[j - 1];
      if (M[s] < 1)
        cout << "errtype" << endl;
      else if (M[s] + c1 < 1)
        cout << "errtype" << endl;
      else {
        cout << "void";
        for (j = 1; j <= M[s] + c1 - 1; j++) cout << '*';
        cout << endl;
      }
    } else {
      cin >> s2 >> s3;
      s = "";
      int c1 = 0;
      for (j = 1; j <= s2.length(); j++)
        if (s2[j - 1] == '&')
          c1--;
        else if (s2[j - 1] == '*')
          c1++;
        else
          s = s + s2[j - 1];
      if (M[s] < 1)
        M[s3] = -1;
      else if (M[s] + c1 < 1)
        M[s3] = -1;
      else
        M[s3] = M[s] + c1;
    }
  }
  return 0;
}
