#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  while (scanf("%d", &n) != EOF) {
    getchar();
    char str[100];
    bool eflag = false;
    bool pflag = false;
    char cmd[10];
    int cnt = 0;
    char exc[51];
    while (n--) {
      gets(str);
      if (pflag || strlen(str) == 0) {
        continue;
      }
      for (int i = 0; str[i]; i++) {
        if (str[i] != ' ') {
          int j = 0;
          while (str[i] <= 'z' && str[i] >= 'a') {
            cmd[j++] = str[i++];
          }
          cmd[j] = 0;
          if (strcmp(cmd, "throw") == 0) {
            eflag = true;
            j = 0;
            for (; str[i]; i++) {
              if (str[i] <= 'z' && str[i] >= 'a' ||
                  str[i] <= 'Z' && str[i] >= 'A') {
                exc[j++] = str[i];
              }
            }
            exc[j] = 0;
            break;
          } else if (eflag) {
            if (strcmp(cmd, "try") == 0) {
              cnt = max(cnt, 0);
              cnt++;
            } else if (strcmp(cmd, "catch") == 0) {
              cnt--;
              if (cnt < 0) {
                j = 0;
                for (; str[i] != ','; i++) {
                  if (str[i] <= 'z' && str[i] >= 'a' ||
                      str[i] <= 'Z' && str[i] >= 'A') {
                    if (str[i] != exc[j++]) {
                      break;
                    }
                  }
                }
                if (exc[j] == 0 && str[i] == ',') {
                  pflag = true;
                  for (; str[i] != '\"'; i++)
                    ;
                  i++;
                  for (; str[i] != '\"'; i++) {
                    putchar(str[i]);
                  }
                  puts("");
                }
              }
            }
          }
          break;
        }
      }
    }
    if (!pflag) {
      puts("Unhandled Exception");
    }
  }
  return 0;
}
