#include <bits/stdc++.h>
using namespace std;
int dy[] = {1, -1, 0, 0, -1, 1, 1, -1};
int dx[] = {0, 0, 1, -1, 1, -1, 1, -1};
void file() {}
void fast() {
  std::ios_base::sync_with_stdio(0);
  cin.tie(NULL);
}
int main() {
  file();
  fast();
  int n;
  cin >> n;
  cin.ignore();
  string Trow = "";
  int before = 0;
  while (n--) {
    string clear = "", str = "";
    getline(cin, str);
    bool ok = 1;
    for (auto& ch : str) {
      if (ch != ' ') ok = 0;
      if (ch == '(' || ch == ')' || ch == ',') {
        clear.push_back(' ');
        clear.push_back(ch);
        clear.push_back(' ');
        continue;
      }
      clear += ch;
    }
    if (ok) continue;
    stringstream ss(clear);
    string op;
    ss >> op;
    if (op == "try") {
      if (Trow != "") before++;
      continue;
    }
    char ch;
    ss >> ch;
    string Variable;
    ss >> Variable;
    if (op == "throw") {
      Trow = Variable;
      continue;
    }
    if (before) {
      before--;
      continue;
    }
    if (Variable != Trow) continue;
    ss >> ch;
    string message = "";
    ok = 0;
    for (auto& ch : clear) {
      if (ch == '"') {
        if (ok) break;
        ok = 1;
        continue;
      }
      if (ok) message.push_back(ch);
    }
    return cout << message, 0;
  }
  return cout << "Unhandled Exception"
              << "\n",
         0;
  return 0;
}
