#include <bits/stdc++.h>
using namespace std;
inline void FAST_IO() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
template <class F, class S>
ostream& operator<<(ostream& os, pair<F, S>& p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
template <class T>
ostream& operator<<(ostream& os, vector<T>& v) {
  os << "(";
  if (v.size()) os << v[0];
  for (int i = 1; i < v.size(); ++i) os << "," << v[i];
  os << ")";
  return os;
}
int main() {
  int n;
  cin >> n;
  cin.get();
  vector<string> a(n);
  for (int i = 0; i < n; ++i) {
    getline(cin, a[i]);
  }
  int lvl = 0;
  int throw_lvl = -1;
  string throw_type = "none";
  stack<int> trys;
  auto isValid = [](char c) {
    return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') ||
           (c >= '1' && c <= '9');
  };
  auto catch_info = [&](int pos) -> pair<string, string> {
    int i = 0;
    while (a[pos][i] != '(') i++;
    while (!isValid(a[pos][i])) i++;
    int j = i;
    while (a[pos][j] != ',') j++;
    while (!isValid(a[pos][j])) j--;
    pair<string, string> ret{a[pos].substr(i, j - i + 1), ""};
    while (a[pos][j] != '\"') j++;
    i = j++;
    while (a[pos][j] != '\"') j++;
    i++;
    j--;
    if (i <= j) ret.second = a[pos].substr(i, j - i + 1);
    return ret;
  };
  auto throw_info = [&](int pos) -> string {
    int i = 0;
    while (a[pos][i] != '(') i++;
    while (!isValid(a[pos][i])) i++;
    int j = i;
    while (a[pos][j] != ')') j++;
    while (!isValid(a[pos][j])) j--;
    return a[pos].substr(i, j - i + 1);
  };
  for (int i = 0; i < n; ++i) {
    int j = 0;
    while (j < a[i].size()) {
      if (isValid(a[i][j])) {
        string cmd = a[i].substr(j, 2);
        if (cmd == "tr") {
          trys.push(++lvl);
        }
        if (cmd == "th") {
          throw_lvl = lvl;
          throw_type = throw_info(i);
        }
        if (cmd == "ca") {
          if (throw_lvl != -1) {
            pair<string, string> p = catch_info(i);
            if (throw_lvl == trys.top()) {
              if (p.first == throw_type) {
                cout << p.second << endl;
                return 0;
              } else {
                throw_lvl--;
              }
            }
          }
          trys.pop();
          --lvl;
        }
        break;
      }
      j++;
    }
  }
  cout << "Unhandled Exception" << endl;
  return 0;
}
