#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:160000000")
using namespace std;
int line_cnt;
struct analys_res {
  bool message_type;
  string module;
  string message;
};
analys_res resultat_of_analys;
void delete_all_space(string &s) {
  string q;
  int t = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] > 32 || t > 0) q += s[i];
    if (s[i] == 34) t = 1 - t;
  }
  s = q;
}
bool AnswerNotUE = false;
int bad_tryes = 0;
bool throw_was = false;
string main_modulo = "";
void message_analys(string s) {
  if (s.substr(0, 3) == "try") {
    if (throw_was) bad_tryes++;
  }
  if (s.substr(0, 5) == "throw") {
    throw_was = true;
    int l = s.find('(');
    int r = s.find(')');
    main_modulo = s.substr(l + 1, r - l - 1);
  }
  if (s.substr(0, 5) == "catch") {
    if (bad_tryes) {
      bad_tryes--;
      return;
    }
    if (!throw_was) {
      return;
    }
    string modulo, ans;
    int l = s.find('(');
    int r = s.find(',');
    modulo = s.substr(l + 1, r - l - 1);
    if (modulo == main_modulo) {
      l = r;
      r = s.find(')');
      l++;
      r--;
      cout << s.substr(l + 1, r - l - 1) << endl;
      AnswerNotUE = true;
      return;
    }
  }
}
int main() {
  cin >> line_cnt;
  string prb;
  getline(cin, prb);
  for (int cur_line = 0; cur_line < line_cnt; cur_line++) {
    string s;
    getline(cin, s);
    delete_all_space(s);
    if (s.empty()) continue;
    if (!AnswerNotUE) message_analys(s);
  }
  if (AnswerNotUE) return 0;
  cout << "Unhandled Exception" << endl;
  return 0;
}
