#include <bits/stdc++.h>
using namespace std;
int got;
char s[103], x[103], y[103], ss[103], ans[103];
bool check() {
  int judge = 0;
  while (~scanf("%*[^a-z]%[a-z]", s), s[1] != 'a') {
    if (s[1] == 'r') judge |= check();
    if (s[1] == 'h') scanf("%*[^a-zA-Z]%[a-zA-Z]", x), judge = 1;
  }
  scanf("%*[^a-zA-Z]%[a-zA-z]%*[^\"]\"%[^\"]", y, ss);
  if (judge && !got && !strcmp(x, y)) {
    got = 1;
    strcpy(ans, ss);
  }
  return judge;
}
int main() {
  int n;
  cin >> n;
  while (~scanf("%*[^a-z]%[a-z]", s), s[1] == 'r') {
    check();
  }
  printf((!ans[0]) ? "Unhandled Exception" : "%s", ans);
}
