#include <bits/stdc++.h>
using namespace std;
const int MAXN = 10007;
const int MOD = 1000000007;
const int INF = 2147483647;
const double EPS = 1e-8;
const string TRY = "try";
const string THROW = "throw";
const string CATCH = "catch";
const string QUOTE = "\"";
const string COMMA = ",";
const string LEFT_BRACKET = "(";
const string RIGHT_BRACKET = ")";
int i, j, k, n, m, p, t, x, y, z, cnt, tcase, xcase;
string os, ts, ans, tag;
stack<int> stk;
istringstream iss;
bool hvf;
int main() {
  while (cin >> n) {
    getline(cin, os);
    while (!stk.empty()) {
      stk.pop();
    }
    hvf = false;
    ans = "";
    for (i = 0; i < n; i++) {
      getline(cin, os);
      if (hvf) {
        continue;
      }
      iss.clear();
      iss.str(os);
      iss >> ts;
      if (ts == TRY) {
        stk.push(0);
      } else if (ts.substr(0, 5) == THROW) {
        m++;
        stk.push(1);
        if (ts.length() > 5) {
          ts.erase(0, 5);
        } else {
          iss >> ts;
        }
        x = os.find(LEFT_BRACKET);
        y = os.rfind(RIGHT_BRACKET);
        ts = os.substr(x + 1, y - x - 1);
        while (ts[0] == ' ') {
          ts.erase(0, 1);
        }
        while (ts[ts.length() - 1] == ' ') {
          ts.erase(ts.length() - 1, 1);
        }
        tag = ts;
      } else if (ts.substr(0, 5) == CATCH) {
        if (stk.top() == 0) {
          stk.pop();
        } else {
          x = os.find(LEFT_BRACKET);
          y = os.find(COMMA, x + 1);
          ts = os.substr(x + 1, y - x - 1);
          while (ts[0] == ' ') {
            ts.erase(0, 1);
          }
          while (ts[ts.length() - 1] == ' ') {
            ts.erase(ts.length() - 1, 1);
          }
          if (ts == tag) {
            x = os.find(QUOTE, x + 1);
            y = os.rfind(QUOTE);
            ans = os.substr(x + 1, y - x - 1);
            hvf = true;
          } else {
            z = stk.top();
            stk.pop();
            if (!stk.empty()) {
              stk.pop();
            }
            stk.push(z);
          }
        }
      }
    }
    if (!hvf) {
      cout << "Unhandled Exception" << endl;
    } else {
      cout << ans << endl;
    }
  }
  return 0;
}
