#include <bits/stdc++.h>
using namespace std;
int x, y, l, i, j, n, k, k1, k2, k3, m, fldgjdflgjhrthrl, fldggfhfghjdflgjl,
    fldgjdflgrtyrtyjl, ffgfldgjdflgjl, r, z, max1, tx, pnt, flag;
int a[200500], b[200500], t[400500], to_push[400500];
string s;
vector<string> f;
char c;
int pos;
string lex;
void getChar() {
  if (pos < s.size())
    c = s[pos++];
  else
    c = '\n';
}
bool isAlpha(char c) {
  if (c >= 'a' && c <= 'z') return true;
  if (c >= 'A' && c <= 'Z') return true;
  return false;
}
void getLex() {
  while (c == ' ') getChar();
  if (c == '(') {
    lex = "(";
    getChar();
  } else if (c == ')') {
    lex = ")";
    getChar();
  } else if (c == ',') {
    lex = ",";
    getChar();
  } else if (c == '"') {
    getChar();
    string tmp;
    while (c != '"') {
      tmp.push_back(c);
      getChar();
    }
    lex = tmp;
  } else {
    lex.clear();
    while (isAlpha(c)) {
      lex.push_back(c);
      getChar();
    }
  }
}
int main() {
  cin >> n;
  getline(cin, s);
  string ans;
  for (i = 0; i < n; i++) {
    getline(cin, s);
    int sz = s.size();
    if (sz == 0) continue;
    pos = 0;
    getChar();
    getLex();
    string x = lex;
    if (x == "try")
      k++;
    else if (x == "throw") {
      getLex();
      getLex();
      ans = lex;
      m = k;
    } else if (x == "catch") {
      getLex();
      getLex();
      if (lex == ans && m == k) {
        getLex();
        getLex();
        cout << lex << endl;
        return 0;
      }
      k--;
      m = min(m, k);
    }
  }
  cout << "Unhandled Exception" << endl;
  return 0;
}
