#include <bits/stdc++.h>
using namespace std;
const long long inf = 0x3f3f3f3f;
const int N = 5e5 + 10;
int a[8008];
int n, ans = 0;
string s, ss, sss;
map<string, int> mp;
void str() {
  cin >> ss;
  int sum = 0;
  string x = "";
  for (int i = 0; i < ss.length(); i++) {
    if (ss[i] == '&')
      sum--;
    else if (ss[i] == '*')
      sum++;
    else
      x += ss[i];
  }
  ans = mp[x];
  if (ans > 0)
    ans += sum;
  else
    ans = 0;
}
int main() {
  mp["void"] = 1;
  cin >> n;
  while (n--) {
    cin >> s;
    ans = 0;
    if (s == "typedef") {
      str();
      cin >> sss;
      mp[sss] = ans;
    } else {
      str();
      ans--;
      if (ans < 0)
        cout << "errtype" << endl;
      else {
        cout << "void";
        for (int i = 0; i < ans; i++) cout << '*';
        cout << endl;
      }
    }
  }
  return 0;
}
