#include <bits/stdc++.h>
using namespace std;
string s, a, b;
map<string, int> ds;
int main() {
  int n;
  cin >> n;
  s = "void";
  ds[s] = 0;
  s = "errtype";
  ds[s] = -1;
  while (n--) {
    cin >> s;
    if (s.length() == 7) {
      cin >> a >> b;
      int tmp = 0;
      while (a.empty() == false && a.back() == '*') {
        tmp++;
        a.pop_back();
      }
      while (a.empty() == false && a.front() == '&') {
        tmp--;
        a.erase(0, 1);
      }
      if (a.empty() || ds.count(a) == 0)
        ds[b] = -1;
      else {
        int tmp2 = ds[a];
        if (tmp2 < 0)
          tmp = -1;
        else
          tmp += tmp2;
        if (tmp < 0) tmp = -1;
        ds[b] = tmp;
      }
    } else {
      cin >> a;
      int tmp = 0;
      while (a.empty() == false && a.back() == '*') {
        tmp++;
        a.pop_back();
      }
      while (a.empty() == false && a.front() == '&') {
        tmp--;
        a.erase(0, 1);
      }
      if (a.empty() || ds.count(a) == 0)
        cout << "errtype\n";
      else {
        int tmp2 = ds[a];
        if (tmp2 < 0)
          tmp = -1;
        else
          tmp += tmp2;
        if (tmp < 0)
          cout << "errtype\n";
        else {
          cout << "void";
          while (tmp--) cout << '*';
          cout << '\n';
        }
      }
    }
  }
  return 0;
}
