#include <bits/stdc++.h>
using namespace std;
map<string, int> types;
int n;
int main() {
  scanf("%d", &n);
  types["void"] = 0;
  types["errtype"] = -1;
  for (int t = 0; t < n; t++) {
    string a, b, c;
    cin >> a;
    if (a.length() == 6) {
      cin >> b;
      int amp = 0;
      for (int i = 0; i < b.size(); i++)
        if (b[i] == '&')
          amp++;
        else
          break;
      int z = 0;
      for (int i = b.size() - 1; i >= 0; i--)
        if (b[i] == '*')
          z++;
        else
          break;
      string nw = "";
      for (int i = 0; i < b.length(); i++) {
        if (b[i] != '*' && b[i] != '&') {
          nw += b[i];
        }
      }
      if (types.count(nw) == 0)
        cout << "errtype" << endl;
      else {
        int cur = types[nw];
        if (cur == -1) {
          printf("errtype\n");
        } else {
          cur += z - amp;
          if (cur < 0)
            printf("errtype\n");
          else {
            printf("void");
            for (int j = 0; j < cur; j++) printf("*");
            printf("\n");
          }
        }
      }
    } else {
      cin >> b >> c;
      int amp = 0;
      for (int i = 0; i < b.size(); i++)
        if (b[i] == '&')
          amp++;
        else
          break;
      int z = 0;
      for (int i = b.size() - 1; i >= 0; i--)
        if (b[i] == '*')
          z++;
        else
          break;
      string nw = "";
      for (int i = 0; i < b.length(); i++) {
        if (b[i] != '*' && b[i] != '&') {
          nw += b[i];
        }
      }
      int cur = -1;
      if (types.count(nw)) {
        cur = types[nw];
      }
      if (cur == -1) {
        types[c] = -1;
      } else {
        cur += z - amp;
        if (cur < 0)
          types[c] = -1;
        else
          types[c] = cur;
      }
    }
  }
  return 0;
}
