#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d\n", &n);
  stack<int> st;
  string tr;
  int trid = -1;
  bool handled = false;
  for (int i = 0; i < n; i++) {
    string line;
    getline(cin, line);
    if (line == "") continue;
    int j = 0;
    string comm;
    while (line[j] == ' ') j++;
    for (; line[j] != '(' && line[j] != ' ' && j < line.size(); j++)
      comm.push_back(line[j]);
    while (line[j] == '(' || line[j] == ' ') j++;
    if (comm == "try") {
      st.push(i);
    } else if (comm == "throw") {
      trid = i;
      bool ok = false;
      for (; line[j] != ')' && j < line.size(); j++) {
        if (line[j] == ' ' && tr.size() == 0) continue;
        if (line[j] == ' ' && tr.size() != 0) break;
        tr.push_back(line[j]);
      }
    } else if (comm == "catch") {
      int start = st.top();
      st.pop();
      if (trid < start) continue;
      string trr, mess;
      for (; line[j] != ')' && j < line.size(); j++) {
        if (trr.size() != 0 && (line[j] == ' ' || line[j] == ',')) break;
        if (line[j] != ' ') {
          trr.push_back(line[j]);
        }
      }
      bool ok = false;
      for (; line[j] != ')' && j < line.size(); j++) {
        if (line[j] == '"') {
          ok = !ok;
          continue;
        }
        if (ok) mess.push_back(line[j]);
      }
      if (tr == trr) {
        cout << mess << "\n";
        handled = true;
        break;
      }
    }
  }
  if (!handled) cout << "Unhandled Exception\n";
  return 0;
}
