#include <bits/stdc++.h>
using namespace std;
int N;
map<string, int> mp;
string eval(string a) {
  int i = 0;
  while (a[0] == '&') --i, a = a.substr(1, a.length() - 1);
  while (a[a.length() - 1] == '*') ++i, a = a.substr(0, a.length() - 1);
  map<string, int>::iterator I = mp.find(a);
  if (I == mp.end())
    return "errtype";
  else {
    int val = I->second;
    if (val == -1)
      return "errtype";
    else {
      val += i;
      if (val < 0)
        return "errtype";
      else {
        a = "void";
        for (int j = 1; j <= val; ++j) a += "*";
        return a;
      }
    }
  }
}
int main() {
  cin >> N;
  string s, a, b;
  mp["void"] = 0, mp["errtype"] = -1;
  while (N--) {
    cin >> s;
    if (s == "typeof") {
      cin >> a;
      cout << eval(a) << "\n";
    } else {
      cin >> a >> b;
      a = eval(a);
      if (a == "errtype")
        mp[b] = -1;
      else
        mp[b] = a.length() - 4;
    }
  }
  return 0;
}
