#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:64000000")
int n, N;
map<string, int> id;
string s;
string s1, s2;
pair<int, int> a[1 << 10];
inline pair<int, int> parse(string &s) {
  pair<int, int> res(0, 0);
  int l = (int)s.length();
  for (int i = 0; i < l; ++i) {
    if (s[i] == '&') ++res.first;
    if (s[i] == '*') ++res.second;
  }
  return res;
}
inline string clean(string s) {
  string res = "";
  int l = (int)s.length();
  for (int i = 0; i < l; ++i) {
    if (s[i] == '&') continue;
    if (s[i] == '*') continue;
    res += s[i];
  }
  return res;
}
inline int getID(string &s) {
  if (!id.count(s)) {
    id[s] = n++;
  }
  return id[s];
}
int main() {
  n = 0;
  a[0] = pair<int, int>(0, 0);
  s = "void";
  getID(s);
  a[1] = pair<int, int>(-1, -1);
  s = "errtype";
  getID(s);
  cin >> N;
  for (int i = 0; i < N; ++i) {
    cin >> s;
    if (s == "typeof") {
      cin >> s1;
      pair<int, int> dif = parse(s1);
      s1 = clean(s1);
      if (!id.count(s1)) {
        puts("errtype");
        continue;
      }
      int ind = id[s1];
      if (a[ind].first == -1) {
        puts("errtype");
        continue;
      }
      pair<int, int> cur = a[ind];
      cur.first += dif.first;
      cur.second += dif.second;
      if (cur.first > cur.second) {
        puts("errtype");
        continue;
      }
      int k = cur.second - cur.first;
      printf("void");
      for (int i = 0; i < k; ++i) printf("*");
      puts("");
      continue;
    }
    cin >> s1 >> s2;
    pair<int, int> cur = parse(s1);
    s1 = clean(s1);
    int ind2 = getID(s2);
    int ind1;
    if (!id.count(s1)) {
      ind1 = 1;
    } else {
      ind1 = getID(s1);
    }
    if (a[ind1].first == -1 || a[ind1].first > a[ind1].second) {
      a[ind2] = pair<int, int>(-1, -1);
      continue;
    }
    a[ind2] = a[ind1];
    a[ind2].second += cur.second;
    a[ind2].first += cur.first;
    if (a[ind2].first > a[ind2].second) {
      a[ind2] = pair<int, int>(-1, -1);
    }
  }
  return 0;
}
