#include <bits/stdc++.h>
using namespace std;
char s[90], r[90], a[90], b[90], ans[90] = {"Unhandled Exception"};
int n;
bool flag = false;
bool check() {
  bool ok = false;
  while (scanf("%*[^a-z]%[a-z]", s), s[1] != 'a') {
    if (s[1] == 'r') ok |= check();
    if (s[1] == 'h') {
      scanf("%*[^A-Za-z]%[A-Za-z]", r);
      ok = true;
    }
  }
  scanf("%*[^A-Za-z]%[A-Za-z]", a);
  scanf("%*[^\"]\"%[^\"]", b);
  if (ok && !flag && strcmp(a, r) == 0) {
    flag = true;
    strcpy(ans, b);
  }
  return ok;
}
int main() {
  scanf("%d", &n);
  while (scanf("%*[^a-z]%[a-z]", s) != EOF && s[1] == 'r') check();
  scanf("%*[^\n]\n");
  printf("%s\n", ans);
  return 0;
}
