#include <bits/stdc++.h>
using namespace std;
string findType(string s, string keyword) {
  int p = s.find(keyword);
  p += keyword.length();
  while (s[p] == ' ' || s[p] == '(') p++;
  int dem = min(min(s.find(' ', p), s.find(',', p)), s.find(')', p));
  string e_type = s.substr(p, dem - p);
  return e_type;
}
int main() {
  int n, count = 0;
  string ans = "", temp;
  bool throw_found = false;
  cin >> n;
  cin.ignore();
  string e_type, c_type;
  for (int i = 0; i < n; i++) {
    string s;
    getline(cin, s);
    int min_in = INT_MAX, min_type = -1;
    if (s.find("try") != string::npos && min_in > s.find("try")) {
      min_in = s.find("try");
      min_type = 0;
    }
    if (s.find("throw") != string::npos && min_in > s.find("throw")) {
      min_in = s.find("throw");
      min_type = 1;
    }
    if (s.find("catch") != string::npos && min_in > s.find("catch")) {
      min_in = s.find("catch");
      min_type = 2;
    }
    if (min_type == 0) {
      if (throw_found == true) {
        count++;
      }
    } else if (min_type == 1) {
      e_type = findType(s, "throw");
      throw_found = true;
    } else if (min_type == 2) {
      if (throw_found == true) {
        if (count > 0)
          count--;
        else {
          c_type = findType(s, "catch");
          if (e_type == c_type) {
            int p = s.find(e_type);
            p = s.find("\"", p);
            int dem = s.find("\"", p + 1);
            ans = s.substr(p + 1, dem - p - 1);
            break;
          }
        }
      }
    }
  }
  if (ans.length() == 0)
    cout << "Unhandled Exception";
  else
    cout << ans;
  return 0;
}
