#include <bits/stdc++.h>
using namespace std;
int n;
string in;
int p;
void skip() {
  while (p < (int)((in).size()) && isspace(in[p])) ++p;
}
int main() {
  int n;
  cin >> n;
  getline(cin, in);
  int df = 100000;
  int cs = 1;
  string ex;
  int fl = 0;
  for (int i = 0; i < (int)n; ++i) {
    getline(cin, in);
    p = 0;
    skip();
    if (p >= (int)((in).size())) continue;
    if (in[p + 1] == 'r') {
      ++cs;
    } else if (in[p + 1] == 'h') {
      p += 5;
      skip();
      ++p;
      skip();
      while (isalpha(in[p])) ex += in[p++];
      df = cs;
    } else {
      p += 5;
      skip();
      p += 1;
      skip();
      string ca;
      while (isalpha(in[p])) ca += in[p++];
      skip();
      ++p;
      skip();
      ++p;
      string str;
      while (in[p] != '"') str += in[p++];
      if (cs <= df && ca == ex) {
        cout << str << endl;
        return 0;
      }
      --cs;
      df = min(df, cs);
      if ((int)((ex).size())) fl = 1;
    }
  }
  cout << "Unhandled Exception" << endl;
}
