#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
using namespace std;
long double EPS = 1e-7;
string a[100000];
int A[100000];
stack<int> st;
bool find(string s1, string s2) {
  for (int i = 0; i < s1.length(); i++) {
    if (i + s2.length() - 1 >= s1.length()) break;
    bool ok = 1;
    for (int j = 0; j < s2.length(); j++) {
      if (s1[i + j] != s2[j]) {
        ok = 0;
        break;
      }
    }
    if (ok) return 1;
  }
  return 0;
}
string get_throw(string s) {
  while (s[0] != '(') s.erase(s.begin());
  s.erase(s.begin());
  while (s[0] == ' ') s.erase(s.begin());
  reverse(s.begin(), s.end());
  while (s[0] != ')') s.erase(s.begin());
  s.erase(s.begin());
  while (s[0] == ' ') s.erase(s.begin());
  reverse(s.begin(), s.end());
  return s;
}
string get_catch_type(string s) {
  while (s[0] != '(') s.erase(s.begin());
  s.erase(s.begin());
  while (s[0] == ' ') s.erase(s.begin());
  reverse(s.begin(), s.end());
  while (s[0] != ',') s.erase(s.begin());
  s.erase(s.begin());
  while (s[0] == ' ') s.erase(s.begin());
  reverse(s.begin(), s.end());
  return s;
}
string get_catch_string(string s) {
  while (s[0] != '"') s.erase(s.begin());
  s.erase(s.begin());
  reverse(s.begin(), s.end());
  while (s[0] != '"') s.erase(s.begin());
  s.erase(s.begin());
  reverse(s.begin(), s.end());
  return s;
}
int main() {
  int n;
  cin >> n;
  getchar();
  for (int i = 0; i < n; i++) {
    getline(cin, a[i]);
  }
  int x;
  for (int i = 0; i < n; i++) {
    if (find(a[i], "catch")) {
      A[i] = st.top();
      st.pop();
    } else if (find(a[i], "throw"))
      x = i, A[i] = -1;
    else if (find(a[i], "try"))
      st.push(i), A[i] = -1;
    else
      A[i] = -1;
  }
  string S = get_throw(a[x]);
  for (int i = 0; i < n; i++) {
    if (A[i] == -1) continue;
    if (i > x && A[i] < x && get_catch_type(a[i]) == S) {
      cout << get_catch_string(a[i]) << endl;
      return 0;
    }
  }
  cout << "Unhandled Exception" << endl;
  return 0;
}
