#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, a, b, from, to, f;
  map<string, long long> mp, use;
  s = "void";
  mp[s] = 0;
  use["void"] = 1;
  use["errtype"] = 1;
  mp["errtype"] = -1;
  long long i, j, k, n, cnt, len;
  cin >> n;
  for (int l = 0; l < n; l++) {
    cin >> s;
    i = 0, j = 0, k = 0, cnt = 0;
    if (s == "typedef") {
      cin >> a >> b;
      len = a.length();
      while (a[i] == '&' && i < len) {
        cnt--;
        i++;
      }
      j = i;
      while (a[j] != '*' && j < len) j++;
      from = a.substr(i, j - i);
      if (use[from] == 1) use[b] = 1;
      k = len - j;
      if (mp[from] < 0) {
        mp[b] = -1;
      } else {
        mp[b] = mp[from] + (k + cnt);
      }
    } else if (s == "typeof") {
      cin >> a;
      len = a.length();
      cnt = 0;
      while (a[i] == '&' && i < len) {
        cnt--;
        i++;
      }
      j = i;
      while (a[j] != '*' && j < len) {
        j++;
      }
      k = len - j;
      from = a.substr(i, j - i);
      if ((mp[from] + cnt + k) < 0 || use[from] == 0 || mp[from] < 0) {
        cout << "errtype" << endl;
      } else {
        cout << "void";
        for (int g = 0; g < (cnt + mp[from] + k); ++g) {
          cout << "*";
        }
        cout << endl;
      }
    }
  }
}
