#include <bits/stdc++.h>
using namespace std;
int id;
string s, catc, err = "lorem";
stack<int> now;
set<int> errId;
void preprocess() {
  for (char& c : s)
    if (c == '(' || c == ')' || c == ',' || c == '\"') c = ' ';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  cin.ignore();
  while (n--) {
    getline(cin, s);
    preprocess();
    stringstream ss(s);
    string cmd;
    ss >> cmd;
    if (cmd == "try") {
      now.push(id);
      ++id;
    } else if (cmd == "throw") {
      ss >> err;
      queue<int> q;
      while (!now.empty()) {
        q.push(now.top());
        errId.insert(now.top());
        now.pop();
      }
      while (!q.empty()) {
        now.push(q.front());
        q.pop();
      }
    } else if (cmd == "catch") {
      ss >> catc;
      int topId = now.top();
      now.pop();
      if (catc == err) {
        if (errId.count(topId)) {
          string ans;
          while (ss >> catc) ans += catc + ' ';
          ans.pop_back();
          cout << ans;
          return 0;
        }
      }
    } else
      continue;
  }
  cout << "Unhandled Exception";
  return 0;
}
