#include <bits/stdc++.h>
using namespace std;
int n;
int main() {
  cin >> n >> ws;
  stack<int> st;
  int head = -1;
  string temp;
  for (int i = 0; i < n; i++) {
    string s;
    getline(cin, s);
    for (int j = 0; j < s.size(); j++)
      if (s[j] == '(' || s[j] == ')' || s[j] == ',') s[j] = ' ';
    string command;
    istringstream scin(s);
    scin >> command;
    if (command == "try") st.push(i);
    if (command == "throw") {
      scin >> temp;
      head = i;
    }
    if (command == "catch") {
      string temp1;
      scin >> temp1;
      if (st.top() < head && temp == temp1) {
        s.erase(0, s.find('"') + 1);
        s.erase(s.find('"'), s.size());
        cout << s;
        return 0;
      }
      st.pop();
    }
  }
  cout << "Unhandled Exception";
  return 0;
}
