#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void smn(T &a, const T &b) {
  if (b < a) a = b;
}
template <class T>
inline void smx(T &a, const T &b) {
  if (b > a) a = b;
}
template <class T>
inline T rev(const T &a) {
  T _ = a;
  reverse(_.begin(), _.end());
  return _;
}
const double eps = 1e-9;
const long double leps = 1e-14;
string bc = "(),";
int n;
string s, s2;
string c;
bool en = 0;
int bad;
int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin >> n;
  getline(cin, s2);
  for (int i = 0; i < n; i++) {
    getline(cin, s2);
    s.clear();
    for (int i = 0; i < ((int((s2).size()))); i++) {
      if (s2[i] == bc[0] || s2[i] == bc[1] || s2[i] == bc[2])
        s += " ", s += s2[i], s += " ";
      else
        s += s2[i];
    }
    istringstream sin(s);
    string com;
    sin >> com;
    if (com == "try") {
      if (en) bad++;
      continue;
    }
    if (com == "throw") {
      string b;
      sin >> b >> b;
      en = 1;
      c = b;
      bad = 0;
    }
    if (com == "catch") {
      if (bad > 0) {
        bad--;
        continue;
      }
      string b;
      sin >> b >> b;
      if (b == c) {
        sin >> b;
        getline(sin, b);
        b = b.substr(1, b.size() - 3);
        while (b[b.size() - 1] != '\"') b.resize(b.size() - 1);
        b.resize(b.size() - 1);
        reverse(b.begin(), b.end());
        while (b[b.size() - 1] != '\"') b.resize(b.size() - 1);
        b.resize(b.size() - 1);
        reverse(b.begin(), b.end());
        cout << b << '\n';
        return 0;
      }
    }
  }
  cout << "Unhandled Exception" << '\n';
  return 0;
}
