#include <bits/stdc++.h>
using namespace std;
const int Q_LEN = 100001;
const int C_LEN = 100;
int n;
int q[Q_LEN];
int qIndex = 0;
int tryNum = 0;
int throwNum = -1;
int catchNum = 0;
char str[C_LEN];
char throwStr[C_LEN];
char catchStr[C_LEN];
char catchMsg[C_LEN];
int parse(char str[]) {
  int index = 0;
  while (str[index]) {
    if (('a' <= str[index] && str[index] <= 'z') ||
        ('A' <= str[index] && str[index] <= 'Z'))
      break;
    index++;
  }
  if ((str[index] == 't' || str[index] == 'T')) {
    if ((str[index + 1] == 'r' || str[index + 1] == 'R')) {
      return 1;
    } else if ((str[index + 1] == 'h' || str[index + 1] == 'H')) {
      return 2;
    }
  } else if ((str[index] == 'c' || str[index] == 'C'))
    return 3;
  else
    return 4;
}
int main() {
  scanf("%d\n", &n);
  bool isError = false;
  for (int ti = 0; ti < n; ti++) {
    gets(str);
    if (isError) continue;
    int j = parse(str);
    if (j == 1) {
      q[qIndex++] = tryNum++;
    } else if (j == 2) {
      if (qIndex >= 1)
        throwNum = q[qIndex - 1];
      else
        throwNum = -1;
      char temp[C_LEN];
      strtok(str, "(");
      strcpy(temp, strtok(NULL, ")"));
      int index = 0;
      for (int i = 0; i < strlen(temp); i++) {
        if (('a' <= temp[i] && temp[i] <= 'z') ||
            ('A' <= temp[i] && temp[i] <= 'Z')) {
          throwStr[index++] = temp[i];
        }
      }
      throwStr[index] = NULL;
    } else if (j == 3) {
      catchNum = q[--qIndex];
      if (throwNum >= catchNum) {
        char temp[C_LEN];
        strtok(str, "(");
        strcpy(temp, strtok(NULL, ","));
        int index = 0;
        for (int i = 0; i < strlen(temp); i++) {
          if (('a' <= temp[i] && temp[i] <= 'z') ||
              ('A' <= temp[i] && temp[i] <= 'Z')) {
            catchStr[index++] = temp[i];
          }
        }
        catchStr[index] = NULL;
        strcpy(catchMsg, strtok(NULL, "\""));
        if (catchMsg[0] == ' ') strcpy(catchMsg, strtok(NULL, "\""));
        if (strcmp(catchStr, throwStr) == 0) {
          isError = true;
        }
      }
    }
  }
  if (isError) {
    cout << catchMsg << endl;
  } else {
    cout << "Unhandled Exception" << endl;
  }
  return 0;
}
