#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
map<string, int> dt;
void addType(string s, string p, int x) {
  auto it = dt.find(p);
  if (it == dt.end() || it->second == -1) {
    dt[s] = -1;
    return;
  }
  int k = x + it->second;
  dt[s] = (k >= 0 ? k : -1);
}
string getType(string s, int x) {
  auto it = dt.find(s);
  if (it == dt.end() || it->second == -1) return "errtype";
  int k = it->second;
  if (x + k < 0) return "errtype";
  string res = "void";
  k += x;
  while (k--) res += '*';
  return res;
}
pair<string, int> simplify(string s) {
  int x = 0;
  while (s.back() == '*') {
    s.pop_back();
    x++;
  }
  reverse(s.begin(), s.end());
  while (s.back() == '&') {
    s.pop_back();
    x--;
  }
  reverse(s.begin(), s.end());
  return pair<string, int>(s, x);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  dt["void"] = 0;
  int n;
  string t, p, s;
  cin >> n;
  while (n--) {
    cin >> t;
    if (t == "typedef") {
      cin >> p >> s;
      auto z = simplify(p);
      addType(s, z.first, z.second);
    } else {
      cin >> s;
      auto z = simplify(s);
      cout << getType(z.first, z.second) << '\n';
    }
  }
}
