#include <bits/stdc++.h>
using namespace std;
template <class A, class B>
ostream& operator<<(ostream& o, const pair<A, B>& p) {
  return o << "(" << p.first << ", " << p.second << ")";
}
template <class T>
ostream& operator<<(ostream& o, const vector<T>& v) {
  o << "{";
  for (__typeof(v.end()) it = v.begin(); it != v.end(); it++) o << *it << ", ";
  return o << "}";
}
template <class T>
ostream& operator<<(ostream& o, const pair<T*, int> arr) {
  o << "{";
  for (__typeof((arr.second) - 1) i = (0); i <= ((arr.second) - 1); i++)
    o << arr.first[i] << ", ";
  return o << "}";
}
template <class T>
ostream& operator<<(ostream& o, const set<T>& v) {
  o << "{";
  for (__typeof(v.end()) it = v.begin(); it != v.end(); it++) o << *it << ", ";
  return o << "}";
}
template <class F, class S>
ostream& operator<<(ostream& o, const map<F, S>& v) {
  o << "{";
  for (__typeof(v.end()) it = v.begin(); it != v.end(); it++) o << *it << ", ";
  return o << "}";
}
struct debugger {
  ostream& out;
  bool first;
  void start() { first = true; }
  debugger(ostream& out) : out(out) { start(); }
  void nl() {
    out << '\n';
    start();
  }
  template <class T>
  debugger& operator,(const T& v) {
    if (first)
      first = false;
    else
      out << ", ";
    out << v;
    return *this;
  }
} dbg(cout);
void skip_spaces(string& line, int& i) {
  while (i < ((int)line.size()) &&
         (line[i] == ' ' || line[i] == '(' || line[i] == ')' ||
          line[i] == ',' || line[i] == '"'))
    i++;
}
enum ThrowState { NOT_FOUND = 0, FOUND_NOW = 1, FOUND };
int main() {
  ;
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int tryId = 0;
  bool throwState = false;
  string throwStr = "", catchStr, line;
  int leastTryId;
  stack<int> tryIds;
  getline(cin, line);
  int nLines = atoi(line.c_str());
  for (__typeof((nLines)-1) _ = (0); _ <= ((nLines)-1); _++) {
    getline(cin, line);
    int i = 0;
    skip_spaces(line, i);
    switch (line[i + 1]) {
      case 'r':
        tryIds.push(tryId);
        tryId++;
        break;
      case 'h':
        leastTryId = tryId;
        i += 5;
        skip_spaces(line, i);
        while (line[i] != ' ' && line[i] != ')') {
          throwStr += line[i];
          i++;
        }
        throwState = true;
        break;
      case 'a':
        if (tryIds.empty()) break;
        if (!throwState || tryIds.top() >= leastTryId) {
          tryIds.pop();
          break;
        }
        tryIds.pop();
        i += 5;
        skip_spaces(line, i);
        catchStr = "";
        while (line[i] != ',' && line[i] != ' ') {
          catchStr += line[i];
          i++;
        }
        if (catchStr != throwStr) break;
        skip_spaces(line, i);
        while (line[i] != '"') {
          putchar(line[i]);
          i++;
        }
        return 0;
      default:
        break;
    }
  }
  printf("Unhandled Exception");
  return 0;
}
