#include <bits/stdc++.h>
using namespace std;
int n;
string s[100055];
int main() {
  scanf("%d\n", &n);
  int open = 0;
  string type;
  int cur = -1;
  stack<int> sta;
  for (int i = 0; i < n; i++) {
    getline(cin, s[i]);
    for (int j = 0; j < (int)s[i].size(); j++) {
      if (j + 2 < (int)s[i].size()) {
        if (s[i][j] == 't' && s[i][j + 1] == 'r' && s[i][j + 2] == 'y') {
          open++;
          sta.push(i);
          break;
        }
      }
      if (j + 1 < (int)s[i].size()) {
        if (s[i][j] == 't' && s[i][j + 1] == 'h') {
          type = "";
          bool on9 = false;
          for (int k = j; s[i][k] != ')'; k++) {
            if (on9 && s[i][k] != ' ') {
              type += s[i][k];
            }
            if (s[i][k] == '(') on9 = true;
          }
          cur = i;
          break;
        }
      }
      if (s[i][j] == 'c') {
        bool on9 = false;
        string diu = "";
        if (!open) break;
        if (sta.top() > cur) {
          sta.pop();
          open--;
          break;
        }
        for (int k = j; s[i][k] != ')'; k++) {
          if (s[i][k] == ',') {
            if (diu != type) break;
            bool wtf = false;
            for (int l = k; s[i][l] != ')'; l++) {
              if (wtf && s[i][l] == '"') break;
              if (wtf) printf("%c", s[i][l]);
              if (s[i][l] == '"') wtf = true;
            }
            puts("");
            return 0;
          }
          if (on9 && s[i][k] != ' ') {
            diu += s[i][k];
          }
          if (s[i][k] == '(') on9 = true;
        }
        open--;
        sta.pop();
        break;
      }
    }
  }
  puts("Unhandled Exception");
  return 0;
}
