#include <bits/stdc++.h>
using namespace std;
string trim(string s) {
  while (((int)(s).size()) && strchr(" \t\n\r", s[0])) s = string(s, 1);
  while (((int)(s).size()) && strchr(" \t\n\r", s[((int)(s).size()) - 1]))
    s = string(s, 0, ((int)(s).size()) - 1);
  return s;
}
char buf[1024];
int main() {
  int n;
  while (scanf("%d", &n) >= 1) {
    fgets(buf, sizeof buf, stdin);
    string ctype = "";
    int cid = -1;
    vector<int> stk;
    string ans = "Unhandled Exception";
    for (int i = 0; i < n; i++) {
      fgets(buf, sizeof buf, stdin);
      string s = trim(buf);
      if (!((int)(s).size())) continue;
      if (s[1] == 'r') {
        stk.push_back(i);
      } else if (s[1] == 'h') {
        s = string(s, s.find("(") + 1);
        s = string(s, 0, ((int)(s).size()) - 1);
        s = trim(s);
        ctype = s;
        cid = i;
      } else if (s[1] == 'a') {
        s = string(s, s.find("(") + 1);
        s = string(s, 0, ((int)(s).size()) - 1);
        string a = trim(string(s, 0, s.find(",")));
        string b = trim(string(s, s.find(",") + 1));
        b = string(b, 1, ((int)(b).size()) - 2);
        assert(((int)(stk).size()) > 0);
        if (stk.back() <= cid && ctype == a) {
          ans = b;
          cid = -1;
        }
        stk.pop_back();
      } else
        assert(false);
    }
    printf("%s\n", ans.c_str());
  }
  return 0;
}
