#include <bits/stdc++.h>
using namespace std;
map<string, int> voc;
int main() {
  int n;
  cin >> n;
  voc["void"] = 0;
  for (int i = 0; i < n; i++) {
    string oper;
    cin >> oper;
    if (oper == "typedef") {
      string p1, p2;
      cin >> p1 >> p2;
      int l = p1.size();
      int k, cnt = 0;
      for (k = l - 1;; k--) {
        if (p1[k] != '*') break;
        cnt++;
      }
      int m;
      for (m = 0;; m++) {
        if (p1[m] != '&') break;
        cnt--;
      }
      string name = "";
      for (int j = m; j <= k; j++) name += p1[j];
      if (voc.count(name)) {
        int bal = voc[name];
        bal += cnt;
        if (bal < 0)
          voc[p2] = -int(1e7);
        else
          voc[p2] = bal;
      } else {
        voc[p2] = -int(1e7);
      }
    } else {
      string p1;
      cin >> p1;
      int l = p1.size();
      int k, cnt = 0;
      for (k = l - 1;; k--) {
        if (p1[k] != '*') break;
        cnt++;
      }
      int m;
      for (m = 0;; m++) {
        if (p1[m] != '&') break;
        cnt--;
      }
      string name = "";
      for (int j = m; j <= k; j++) name += p1[j];
      if (voc.count(name)) {
        int bal = voc[name];
        bal += cnt;
        if (bal < 0) {
          cout << "errtype\n";
        } else {
          cout << "void";
          for (int j = 0; j < bal; j++) cout << "*";
          cout << endl;
        }
      } else {
        cout << "errtype\n";
      }
    }
  }
  return 0;
}
