#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
  while (a != 0 && b != 0) {
    if (a > b)
      a %= b;
    else
      b %= a;
  }
  return a + b;
}
vector<string> data;
vector<int> param;
int func(int t, int tmp) {
  if (tmp == -1) return -1;
  if (t + tmp < 0) return -1;
  return t + tmp;
}
void Add(string arg, string from, int t) {
  int tmp = -1;
  for (long long i = 0; i <= data.size() - 1; i++) {
    if (data[i] == from) {
      tmp = i;
      break;
    }
  }
  for (long long i = 0; i <= data.size() - 1; i++) {
    if (data[i] == arg) {
      if (tmp == -1)
        param[i] = -1;
      else
        param[i] = func(t, param[tmp]);
      return;
    }
  }
  if (tmp != -1)
    param.push_back(func(t, param[tmp]));
  else
    param.push_back(-1);
  data.push_back(arg);
  return;
}
string Get(string arg, int cnt) {
  for (long long i = 0; i <= data.size() - 1; i++)
    if (data[i] == arg) {
      if (param[i] == -1 || cnt + param[i] < 0) return "errtype";
      string res = "void";
      for (long long j = 1; j <= param[i] + cnt; j++) res += "*";
      return res;
    }
  return "errtype";
}
int main() {
  vector<string> res;
  data.clear();
  param.clear();
  data.push_back("void");
  data.push_back("errtype");
  param.push_back(0);
  param.push_back(-1);
  int n;
  string s, s1, s2;
  cin >> n;
  for (long long i = 0; i <= n - 1; i++) {
    cin >> s;
    if (s == "typedef") {
      cin >> s1 >> s2;
      int cntamp = 0;
      int cntptr = 0;
      int j = 0;
      while (s1[j] == '&') {
        j++;
        cntamp++;
      }
      s1.erase(0, j);
      j = s1.size() - 1;
      while (s1[j] == '*') {
        cntptr++;
        j--;
      }
      if (cntptr) s1.erase(j + 1, cntptr);
      Add(s2, s1, cntptr - cntamp);
    }
    if (s == "typeof") {
      cin >> s1;
      int cntamp = 0;
      int cntptr = 0;
      int j = 0;
      while (s1[j] == '&') {
        j++;
        cntamp++;
      }
      s1.erase(0, j);
      j = s1.size() - 1;
      while (s1[j] == '*') {
        cntptr++;
        j--;
      }
      if (cntptr) s1.erase(j + 1, cntptr);
      res.push_back(Get(s1, cntptr - cntamp));
    }
  }
  if (res.size())
    for (long long i = 0; i <= res.size() - 1; i++) {
      cout << res[i];
      cout << endl;
    }
}
