#include <bits/stdc++.h>
using namespace std;
const int oo = (int)1e9;
const double PI = 2 * acos(0.0);
const double eps = 1e-9;
const int TRY = 1;
const int THROW = 2;
struct expr {
  int type;
  string exception_str;
  expr(int t, string s = "") {
    if (t == TRY)
      type = t;
    else if (t == THROW) {
      type = t;
      exception_str = s;
    }
  }
};
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  string s;
  getline(cin, s);
  stack<expr> st;
  while (n) {
    --n;
    getline(cin, s);
    int tryidx, catchidx, throwidx;
    tryidx = s.find("try");
    catchidx = s.find("catch");
    throwidx = s.find("throw");
    if (tryidx == -1) tryidx = oo;
    if (catchidx == -1) catchidx = oo;
    if (throwidx == -1) throwidx = oo;
    if (tryidx < catchidx && tryidx < throwidx) {
      st.push(expr(TRY));
    } else if (catchidx < tryidx && catchidx < throwidx) {
      if (st.empty()) continue;
      if (st.top().type == TRY)
        st.pop();
      else {
        string exp_str = "";
        for (int i = s.find("(") + 1; i < (int)(s.find(",")); i++) {
          if (s[i] >= 'a' && s[i] <= 'z') exp_str += s[i];
          if (s[i] >= 'A' && s[i] <= 'Z') exp_str += s[i];
        }
        int quotatinosidx = s.find("\"");
        string exp_msg = "";
        for (int i = quotatinosidx + 1;
             i < (int)(s.find("\"", quotatinosidx + 1)); i++)
          exp_msg += s[i];
        if (st.top().exception_str == exp_str)
          return cout << exp_msg << endl, 0;
      }
    } else if (throwidx < catchidx && throwidx < tryidx) {
      string exp_str = "";
      for (int i = s.find("(") + 1; i < (int)(s.find(")")); i++) {
        if (s[i] >= 'a' && s[i] <= 'z') exp_str += s[i];
        if (s[i] >= 'A' && s[i] <= 'Z') exp_str += s[i];
      }
      st.push(expr(THROW, exp_str));
    }
  }
  cout << "Unhandled Exception" << endl;
  return 0;
}
