#include <bits/stdc++.h>
using namespace std;
bool in_exception;
int exc_level;
int level = 0;
char cur_exception[64];
char line[64];
void next_line(void) { fgets(line, 63, stdin); }
int main() {
  next_line();
  int lines;
  sscanf(line, "%d", &lines);
  while (lines--) {
    next_line();
    if (sscanf(line, " throw ( %[a-zA-Z] )", cur_exception) == 1) {
      exc_level = level - 1;
      in_exception = true;
      continue;
    } else if (strstr(line, "catch") != NULL) {
      level -= 1;
      if (level != exc_level) continue;
      exc_level -= 1;
      char *n = strchr(line, ',');
      char *m = strchr(n + 1, '"');
      *strchr(m + 1, '"') = 0;
      *n = 0;
      while (*(n - 1) == ' ') *(--n) = 0;
      while (isalpha(*(n - 1))) n -= 1;
      if (strcmp(n, cur_exception) == 0) {
        puts(m + 1);
        exit(0);
      }
    } else if (strstr(line, "try") != NULL) {
      level += 1;
      continue;
    }
  }
  puts("Unhandled Exception");
  return 0;
}
