#include <bits/stdc++.h>
using namespace std;
const int UNDEF = -1;
const int INF = 2000000000;
const long long INF64 = 4000000000000000000;
const double PI = 3.1415926535897932384626433832795;
const double EPS = 1e-9;
template <typename T>
T sqr(const T &x) {
  return x * x;
}
template <typename T>
const string GetString(const T &val) {
  ostringstream sout;
  sout << val;
  return sout.str();
}
int main() {
  int n;
  scanf("%d\n", &n);
  int thrw = -1;
  string type;
  vector<int> v;
  for (int i = 0; i < (n); ++i) {
    string s;
    getline(cin, s);
    replace((s).begin(), (s).end(), '(', ' ');
    replace((s).begin(), (s).end(), ')', ' ');
    replace((s).begin(), (s).end(), ',', ' ');
    istringstream stream(s);
    string t;
    stream >> t;
    if (t == "catch") {
      string::iterator l = find((s).begin(), (s).end(), '"') + 1;
      string::iterator r = find(l, s.end(), '"');
      string message = s.substr(l - s.begin(), r - l);
      string curType;
      istringstream stream(s);
      stream >> curType >> curType;
      if (curType == type && v.back() < thrw) {
        cout << message << endl;
        return 0;
      }
      v.pop_back();
    } else if (t == "throw") {
      if (v.empty()) {
        cout << "Unhandled Exception" << endl;
        return 0;
      }
      istringstream stream(s);
      stream >> type >> type;
      thrw = i;
    } else if (t == "try") {
      v.push_back(i);
    }
  }
  cout << "Unhandled Exception" << endl;
  return 0;
}
