#include <bits/stdc++.h>
using namespace std;
map<string, long long> m;
int main() {
  long long n;
  cin >> n;
  m["void"] = 0;
  m["errtype"] = INT_MIN;
  while (n--) {
    string key, type, var;
    cin >> key;
    if (key == "typedef") {
      cin >> type >> var;
      string p;
      long long amp = 0, ptr = 0, start = 0, end = 0;
      for (long long i = 0; i <= type.size() - 1; i++)
        if (type[i] != '&') {
          start = i;
          break;
        } else
          amp++;
      for (long long i = type.size() - 1; i >= 0; i--)
        if (type[i] != '*') {
          end = i;
          break;
        } else
          ptr++;
      for (long long i = start; i <= end; i++) p.push_back(type[i]);
      if (m.find(p) == m.end()) {
        m[var] = INT_MIN;
        continue;
      }
      long long cur = m[p];
      if (cur < 0 || cur + ptr - amp < 0)
        m[var] = INT_MIN;
      else
        m[var] = cur + ptr - amp;
    } else if (key == "typeof") {
      string var;
      cin >> var;
      long long amp = 0, ptr = 0;
      while (*var.begin() == '&') {
        amp++;
        var.erase(var.begin());
      }
      while (*var.rbegin() == '*') {
        ptr++;
        var.erase(--var.end());
      }
      if (m.find(var) == m.end() || m[var] < 0 || m[var] + ptr - amp < 0) {
        cout << "errtype\n";
        continue;
      }
      cout << "void";
      for (long long i = 1; i <= m[var] + ptr - amp; i++) cout << '*';
      cout << "\n";
    }
  }
}
