#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 10;
vector<string> st;
string s, r = "*noting!*", e, ans, ltr;
int n;
int main() {
  cin >> n;
  getline(cin, s);
  for (int i = 1; i <= n; i++) {
    s.clear();
    getline(cin, s);
    stringstream inp;
    inp << s;
    s.clear();
    char c;
    bool w = false;
    while (inp >> c) {
      s += c;
      if (c == '"') {
        w = true;
        break;
      }
    }
    if (w) {
      getline(inp, e);
      s += e;
      e.clear();
    }
    if (s.size() != 0) {
      if (s == "try")
        st.push_back(r);
      else if (s[0] == 't') {
        int j = 6;
        while (s[j] != ')') {
          e += s[j];
          j++;
        }
        for (int j = 0; j < st.size(); j++) st[j] = e;
        e.clear();
      } else {
        int j = 6;
        while (s[j] != ',') {
          e += s[j];
          j++;
        }
        j += 2;
        while (s[j] != '"') {
          ltr += s[j];
          j++;
        }
        if (ans.size() == 0)
          if (e == st[st.size() - 1]) ans = ltr;
        st.pop_back();
        ltr.clear();
        e.clear();
      }
    }
  }
  if (ans.size() == 0)
    cout << "Unhandled Exception" << endl;
  else
    cout << ans << endl;
  return 0;
}
