#include <bits/stdc++.h>
using namespace std;
int n;
map<string, int> mp;
pair<string, int> getp(string s) {
  int x = 0;
  while (s[s.length() - 1] == '*') x++, s = s.substr(0, s.length() - 1);
  while (s[0] == '&') x--, s = s.substr(1);
  assert(s[0] != '*');
  assert(s[s.length() - 1] != '&');
  return make_pair(s, x);
}
int add(int a, int b) {
  if (a == -1) return -1;
  a += b;
  if (a < 0)
    return -1;
  else
    return a;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  if (fopen("input.txt", "r")) freopen("input.txt", "r", stdin);
  mp["void"] = 0;
  mp["errtype"] = -1;
  cin >> n;
  for (int i = 0, _i = (n); i < _i; ++i) {
    string t;
    cin >> t;
    if (t == "typedef") {
      string a, b;
      cin >> a >> b;
      pair<string, int> p = getp(a);
      if (mp.count(p.first)) mp[b] = add(mp[p.first], p.second);
    } else {
      string a;
      cin >> a;
      pair<string, int> p = getp(a);
      if (mp.count(p.first)) {
        int x = add(mp[p.first], p.second);
        if (x == -1)
          cout << "errtype\n";
        else {
          cout << "void";
          for (int j = 0, _j = (x); j < _j; ++j) cout << '*';
          cout << '\n';
        }
      } else
        cout << "errtype\n";
    }
  }
  return 0;
}
