#include <bits/stdc++.h>
using namespace std;
int st[100005];
int st_i = 0;
char strThrow[100];
inline bool isLetter(char ch) {
  if (ch >= 'A' && ch <= 'Z') return true;
  if (ch >= 'a' && ch <= 'z') return true;
  return false;
}
int main() {
  int n;
  char str[305];
  cin.getline(str, 300);
  sscanf(str, "%d", &n);
  for (int i = 0; i < n; i++) {
    cin.getline(str, 300);
    int pst = 0, len = strlen(str);
    for (int k = 0; k < len; k++) {
      if (pst == 0) {
        if (str[k] == ' ') {
          pst = 0;
        } else if (str[k] == 't') {
          pst = 1;
        } else if (str[k] == 'c') {
          pst = 2;
        }
      } else if (pst == 1) {
        if (str[k] == 'r') {
          pst = 3;
        } else if (str[k] == 'h') {
          pst = 4;
        }
      } else if (pst == 2) {
        char strEx[100], strStr[100];
        int strEx_i = 0, strStr_i = 0;
        int stt = 0;
        for (int j = k + 1; j < len; j++) {
          if (stt == 0) {
            if (str[j] == '(') stt = 1;
          } else if (stt == 1) {
            if (isLetter(str[j])) stt = 2;
          }
          if (stt == 2) {
            if (!isLetter(str[j])) {
              strEx[strEx_i] = 0;
              stt = 3;
            } else {
              strEx[strEx_i++] = str[j];
            }
          }
          if (stt == 3) {
            if (str[j] == '"') stt = 4;
          } else if (stt == 4) {
            if (str[j] == '"') {
              strStr[strStr_i] = 0;
              break;
            } else {
              strStr[strStr_i++] = str[j];
            }
          }
        }
        if (st[st_i - 1] == 2) {
          if (!strcmp(strThrow, strEx)) {
            printf("%s\n", strStr);
            return 0;
          } else {
            st_i--;
            st[st_i - 1] = 2;
          }
        } else {
          st_i--;
        }
        break;
      } else if (pst == 3) {
        st[st_i] = 1;
        st_i++;
        break;
      } else if (pst == 4) {
        int stt = 0;
        int _ppp = 0;
        for (int j = k + 1; j < len; j++) {
          if (stt == 0) {
            if (str[j] == '(') stt = 1;
          } else if (stt == 1) {
            if (isLetter(str[j])) stt = 2;
          }
          if (stt == 2) {
            if (!isLetter(str[j])) {
              strThrow[_ppp] = 0;
              st[st_i++] = 2;
              break;
            } else {
              strThrow[_ppp++] = str[j];
            }
          }
        }
        break;
      }
    }
  }
  printf("Unhandled Exception\n");
  return 0;
}
