#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
signed main() {
  long long n;
  cin >> n;
  string ex;
  getline(cin, ex);
  ex.clear();
  stack<bool> st;
  while (n--) {
    string s;
    getline(cin, s);
    while (s.back() == ' ' || s.back() == ')' || s.back() == '"') s.pop_back();
    reverse(s.begin(), s.end());
    while (s.back() == ' ') s.pop_back();
    if (s.size() < 3) continue;
    if (s[s.size() - 2] == 'r') {
      st.push(false);
      continue;
    } else if (s[s.size() - 2] == 'h') {
      s.pop_back();
      s.pop_back();
      s.pop_back();
      s.pop_back();
      s.pop_back();
      while (s.back() == ' ' || s.back() == '(') s.pop_back();
      reverse(s.begin(), s.end());
      st.push(true);
      ex = s;
    } else if (s[s.size() - 2] == 'a') {
      s.pop_back();
      s.pop_back();
      s.pop_back();
      s.pop_back();
      s.pop_back();
      while (s.back() == ' ' || s.back() == '(') s.pop_back();
      reverse(s.begin(), s.end());
      long long i = s.find(',');
      string a = s.substr(0, i), b = s.substr(i + 1);
      while (a.back() == ' ') a.pop_back();
      reverse(b.begin(), b.end());
      while (b.back() == ' ' || b.back() == '"') b.pop_back();
      reverse(b.begin(), b.end());
      if (st.top()) {
        if (ex == a)
          cout << b, exit(0);
        else {
          st.pop(), st.pop(), st.push(true);
        }
      } else {
        st.pop();
      }
    }
  }
  cout << "Unhandled Exception";
}
