#include <bits/stdc++.h>
using namespace std;
map<string, int> def;
string str, A, B, an, as;
int n, x, y;
int countx(string str, string x) {
  int cnt = 0;
  for (int i = 0; i < str.length(); i++)
    if (str[i] == cnt) cnt++;
  return cnt;
}
int main() {
  cin >> n;
  an = "&";
  as = "*";
  def.insert(make_pair("void", 0));
  def.insert(make_pair("errtype", -1));
  for (int loop = 1; loop <= n; loop++) {
    cin >> str;
    if (str == "typedef") {
      cin >> A >> B;
      str = A;
      x = countx(str, "&");
      y = countx(str, "*");
      while (str[0] == an[0]) {
        str.erase(0, 1);
        x++;
      }
      while (str[str.length() - 1] == as[0]) {
        str.erase(str.length() - 1);
        y++;
      }
      map<string, int>::iterator res = def.find(str);
      if (res != def.end() && res->second - x + y >= 0 && res->second >= 0) {
        map<string, int>::iterator iter = def.find(B);
        if (iter == def.end())
          def.insert(make_pair(B, res->second - x + y));
        else {
          iter->second = res->second - x + y;
        }
      } else {
        map<string, int>::iterator iter = def.find(B);
        if (iter == def.end())
          def.insert(make_pair(B, -1));
        else {
          iter->second = -1;
        }
      }
    } else {
      cin >> str;
      x = countx(str, "&");
      y = countx(str, "*");
      while (str[0] == an[0]) {
        str.erase(0, 1);
        x++;
      }
      while (str[str.length() - 1] == as[0]) {
        str.erase(str.length() - 1);
        y++;
      }
      map<string, int>::iterator res = def.find(str);
      if (res != def.end() && res->second - x + y >= 0 && res->second >= 0) {
        cout << "void";
        for (int i = 1; i <= res->second - x + y; i++) cout << "*";
        cout << endl;
      } else
        cout << "errtype" << endl;
    }
  }
}
