#include <bits/stdc++.h>
struct code {
  std::string event;
  std::string key;
  std::string message;
  code() = default;
  code(const std::string& event) : event(event), key(), message() {}
  code(const std::string& ev, const std::string& key, const std::string& msg)
      : event(ev), key(key), message(msg) {}
};
const std::regex endblock(
    R";-;(^\s*catch\s*\(\s*(\w+)\s*,\s*"([a-zA-Z\d\s]+)"\s*\)\s*$);-;",
    std::regex_constants::optimize);
const std::regex event(R";-;(^\s*throw\s*\(\s*(\w+)\s*\)\s*$);-;",
                       std::regex_constants::optimize);
const std::regex startblock(R"(^\s*try\s*$)", std::regex_constants::optimize);
code parser(const std::string& line) {
  std::smatch pieces_match;
  if (std::regex_match(line, pieces_match, startblock)) return code("try");
  if (std::regex_match(line, pieces_match, event)) {
    assert(pieces_match.size() == 2);
    return code("throw", pieces_match[1].str(), "");
  }
  if (std::regex_match(line, pieces_match, endblock)) {
    assert(pieces_match.size() == 3);
    return code("catch", pieces_match[1].str(), pieces_match[2].str());
  }
  return code("noevent");
}
int main() {
  int amount;
  std::cin >> amount;
  std::cin.ignore(100, '\n');
  std::string line;
  std::string key_event;
  int level = 0;
  int counter = 0;
  code parsed;
  for (int i = 0; i < amount; ++i) {
    std::getline(std::cin, line);
    parsed = parser(line);
    if (key_event.size()) {
      if (parsed.event == "try") {
        ++counter;
        continue;
      } else if (parsed.event == "catch" and counter > 0) {
        --counter;
        continue;
      }
    }
    if (parsed.event == "try") {
      ++level;
    } else if (parsed.event == "catch") {
      if (parsed.key == key_event) {
        std::cout << parsed.message;
        std::cin.ignore(std::numeric_limits<std::streamsize>::max());
        break;
      }
      --level;
    } else if (parsed.event == "throw") {
      key_event = parsed.key;
    }
  }
  if (not level) {
    std::cout << "Unhandled Exception";
  }
  return 0;
}
