#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
const int inf = 1000 * 1000 * 1000;
map<string, int> mp;
set<string> st;
void ok(string B) {
  if (st.find(B) == st.end()) st.insert(B);
}
bool c(string s) { return (st.find(s) == st.end()); }
int main() {
  int n;
  scanf("%d", &n);
  mp["void"] = 0;
  st.insert("void");
  for (int y = 0; y < n; y++) {
    string temp;
    cin >> temp;
    if (temp == "typedef") {
      string A, B;
      cin >> A >> B;
      int k1 = 0, k2 = 0;
      string name;
      for (int i = 0; i < (int)A.size(); i++) {
        if (A[i] == '&')
          k1++;
        else if (A[i] == '*')
          k2++;
        else
          name.push_back(A[i]);
      }
      if (c(name)) {
        mp[B] = inf;
        ok(B);
      } else if (mp[name] == inf) {
        mp[B] = inf;
        ok(B);
      } else {
        k2 = k2 + mp[name] - k1;
        if (k2 < 0)
          mp[B] = inf;
        else
          mp[B] = k2;
        ok(B);
      }
    } else {
      string A;
      cin >> A;
      int k1 = 0, k2 = 0;
      string name;
      for (int i = 0; i < (int)A.size(); i++) {
        if (A[i] == '&')
          k1++;
        else if (A[i] == '*')
          k2++;
        else
          name.push_back(A[i]);
      }
      if (mp[name] == inf || c(name)) {
        cout << "errtype";
      } else {
        k2 = k2 + mp[name] - k1;
        if (k2 < 0)
          cout << "errtype";
        else {
          cout << "void";
          for (int i = 0; i < k2; i++) cout << '*';
        }
      }
      cout << endl;
    }
  }
  return 0;
}
