#include <bits/stdc++.h>
using namespace std;
bool check(char c) { return c != '\n'; }
char str[105], type[105], temp[105];
int main() {
  int T;
  scanf("%d", &T);
  char c;
  bool flag = false, throwflag = false;
  while (check(c = getchar()))
    ;
  int cnt = 0;
  while (T--) {
    bool qaq = false;
    int len = -1;
    while (check(c = getchar())) {
      if (qaq && c != '"')
        str[++len] = c;
      else if (c == ' ')
        continue;
      else if (c == '"') {
        qaq = !qaq;
        str[++len] = c;
      } else
        str[++len] = c;
    }
    str[++len] = '\0';
    if (throwflag == true && flag == false) {
      if (str[1] == 'r') cnt++;
      if (str[0] == 'c') {
        if (cnt > 0)
          cnt--;
        else {
          int i = 6;
          int lentemp = -1;
          for (; str[i] != ','; i++) temp[++lentemp] = str[i];
          temp[++lentemp] = '\0';
          if (strcmp(temp, type) == 0) {
            for (i = i + 2; str[i] != '"'; i++) printf("%c", str[i]);
            puts("");
            flag = true;
          }
        }
      }
    }
    if (str[1] == 'h') {
      int lentype = -1;
      for (int i = 6; str[i] != ')'; i++) type[++lentype] = str[i];
      type[++lentype] = '\0';
      throwflag = true;
    }
  }
  if (flag == false) printf("Unhandled Exception\n");
}
