#include <bits/stdc++.h>
using namespace std;
map<string, int> m;
int main() {
  ios_base::sync_with_stdio(0);
  int q;
  cin >> q;
  string in;
  m["void"] = 0;
  while (q--) {
    cin >> in;
    if (in == "typedef") {
      cin >> in;
      int r = 0, deref = 0;
      for (int i = 0; i < in.size(); i++) {
        if (in[i] == '&')
          deref++;
        else
          break;
      }
      for (int i = in.size() - 1; i >= 0; i--) {
        if (in[i] == '*')
          r++;
        else
          break;
      }
      string nxt = "";
      for (int i = 0; i < in.size(); i++)
        if (in[i] != '*' && in[i] != '&') nxt += in[i];
      in = nxt;
      int a;
      if (m.find(in) == m.end())
        a = -1;
      else
        a = m[in];
      cin >> in;
      if (a == -1)
        m[in] = a;
      else {
        a += r - deref;
        if (a < 0) a = -1;
        m[in] = a;
      }
    } else {
      cin >> in;
      int r = 0, deref = 0;
      for (int i = 0; i < in.size(); i++) {
        if (in[i] == '&')
          deref++;
        else
          break;
      }
      for (int i = in.size() - 1; i >= 0; i--) {
        if (in[i] == '*')
          r++;
        else
          break;
      }
      string nxt = "";
      for (int i = 0; i < in.size(); i++)
        if (in[i] != '*' && in[i] != '&') nxt += in[i];
      in = nxt;
      int a = -1;
      if (m.find(in) != m.end()) a = m[in];
      if (a == -1)
        cout << "errtype\n";
      else {
        a += r - deref;
        if (a < 0)
          cout << "errtype\n";
        else {
          cout << "void";
          for (int i = 0; i < a; i++) cout << '*';
          cout << "\n";
        }
      }
    }
  }
  return 0;
}
