#include <bits/stdc++.h>
const double eps = 1e-9;
const int int_inf = 1 << 31 - 1;
const long long i64_inf = 1ll << 63 - 1;
const double pi = acos(-1.0);
using namespace std;
int n;
string a[100500];
int id[100500];
int sz = 0;
string T;
int ID = -1;
int main() {
  scanf("%d", &n);
  char c = ' ';
  while (1) {
    c = getchar();
    if (c == '\n') break;
  }
  T.clear();
  for (int i = 0; i < (int)n; i++) {
    c = ' ';
    string second = "";
    bool was = 0;
    while (1) {
      c = getchar();
      if (c == '\n') break;
      if (c == '"' && !was)
        was = 1;
      else if (c == '"' && was)
        was = 0;
      if (c != ' ' || was) second += c;
    }
    if (second.empty()) continue;
    if (second == "try") a[sz] = second, id[sz] = i, sz++;
    if (second[0] == 't' && second[1] == 'h')
      for (int j = 6; j < second.length() - 1; j++) T += second[j], ID = i;
    if (second[0] == 'c') {
      string type = "";
      string text = "";
      int j = 6;
      for (; second[j] != ','; j++) type += second[j];
      for (j += 2; j < second.length() - 2; j++) text += second[j];
      if (ID != -1 && a[sz - 1] == "try" && id[sz - 1] < ID && type == T) {
        cout << text << "\n";
        return 0;
      }
      sz--;
    }
  }
  cout << "Unhandled Exception";
  return 0;
}
