#include <bits/stdc++.h>
using namespace std;
signed main() {
  int N;
  cin >> N;
  stack<int> pos;
  string tp;
  getline(cin, tp);
  int th = -1;
  for (int i = 0; i < N; i++) {
    string line;
    getline(cin, line);
    replace((line).begin(), (line).end(), '(', ' ');
    replace((line).begin(), (line).end(), ')', ' ');
    replace((line).begin(), (line).end(), ',', ' ');
    stringstream tok(line);
    string cmd;
    tok >> cmd;
    if (cmd == "try") {
      pos.push(i);
    } else if (cmd == "throw") {
      tok >> tp;
      th = i;
    } else if (cmd == "catch") {
      string t;
      tok >> t;
      if (t == tp && pos.top() < th) {
        string msg;
        getline(tok, msg);
        msg.erase(0, msg.find('"') + 1);
        msg.erase(msg.find('"'), msg.size());
        cout << msg << "\n";
        return 0;
      }
      pos.pop();
    }
  }
  cout << "Unhandled Exception\n";
}
