#include <bits/stdc++.h>
int n;
int stk[110000];
int list[110000];
int nlist;
char msg[110000][52];
char exc[110000][52];
char str[10000];
char texc[10000];
int top = -1;
int main() {
  scanf("%d", &n);
  gets(str);
  for (int k = 0; k < n; k++) {
    gets(str);
    int m = strlen(str);
    int type = 0;
    for (int i = 0; i < m; i++) {
      if (str[i] != ' ') {
        if (str[i] == 't' && str[i + 1] == 'r') type = 1;
        if (str[i] == 't' && str[i + 1] == 'h') type = 2;
        if (str[i] == 'c') type = 3;
        break;
      }
    }
    if (type == 1) {
      stk[++top] = k;
    }
    if (type == 2) {
      for (int i = 0; i <= top; i++) {
        list[i] = stk[i];
      }
      nlist = top + 1;
      int enable = 0;
      int ct = 0;
      for (int i = 0; i < m; i++) {
        if (str[i] == ')') break;
        if (enable == 1 && str[i] != ' ') texc[ct++] = str[i];
        if (str[i] == '(') enable = 1;
      }
      texc[ct] = '\0';
    }
    if (type == 3) {
      int start = -1;
      int end;
      for (int i = 0; i < m; i++) {
        if (str[i] == '"' && start == -1) start = i + 1;
        if (str[i] == '"' && start != -1) end = i - 1;
      }
      for (int i = start; i <= end; i++) {
        msg[stk[top]][i - start] = str[i];
      }
      msg[stk[top]][end + 1] = '\0';
      int ct = 0;
      int enable = 0;
      for (int i = 0; i < m; i++) {
        if (str[i] == ',') break;
        if (enable == 1 && str[i] != ' ') exc[stk[top]][ct++] = str[i];
        if (str[i] == '(') enable = 1;
      }
      exc[stk[top]][ct] = '\0';
      top--;
    }
  }
  int success = 0;
  for (int i = nlist - 1; i >= 0; i--) {
    if (strcmp(texc, exc[list[i]]) == 0) {
      printf("%s\n", msg[list[i]]);
      success = 1;
      break;
    }
  }
  if (success == 0) {
    printf("Unhandled Exception\n");
  }
}
