#include <bits/stdc++.h>
using namespace std;
long long get() {
  char c = getchar();
  long long x = 0LL;
  while (c < '0' || c > '9') c = getchar();
  while (c >= '0' && c <= '9') {
    x *= 10LL;
    x += (c - '0');
    c = getchar();
  }
  return x;
}
int n;
string t, type, b;
map<string, int> mp;
int main() {
  ios::sync_with_stdio(0);
  mp["void"] = 0;
  mp["errtype"] = -1;
  cin >> n;
  while (n--) {
    cin >> t;
    if (t == "typeof") {
      cin >> b;
      int z = 0, l = 0, nn = 0;
      for (int i = 0; i < b.size(); i++) {
        if (b[i] != '&') break;
        z++;
        nn++;
      }
      string name = "";
      for (int i = nn; i < b.size(); i++) {
        if (b[i] < 'a' || b[i] > 'z') break;
        name += b[i];
        nn++;
      }
      if (mp.find(name) == mp.end()) {
        cout << "errtype\n";
        continue;
      }
      for (int i = nn; i < b.size(); i++) l++;
      l -= z;
      l += mp[name];
      if (l < 0 || mp[name] < 0) {
        cout << "errtype\n";
      } else {
        cout << "void";
        for (int i = 0; i < l; i++) cout << "*";
        cout << "\n";
      }
    } else {
      cin >> type >> b;
      int z = 0, l = 0;
      int nn = 0;
      for (int i = 0; i < type.size(); i++) {
        if (type[i] != '&') break;
        z++;
        nn++;
      }
      string name = "";
      for (int i = nn; i < type.size(); i++) {
        if (type[i] < 'a' || type[i] > 'z') break;
        name += type[i];
        nn++;
      }
      for (int i = nn; i < type.size(); i++) l++;
      if (mp.find(name) == mp.end() || mp[name] < 0) {
        mp[b] = -1;
      } else {
        l += mp[name];
        l -= z;
        if (l < 0)
          mp[b] = -1;
        else
          mp[b] = l;
      }
    }
  }
  return 0;
}
