#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000;
const int RW = -1;
struct T {
  int begin, over, link;
  T() : begin(0), over(0), link(-1) {}
  void re(int a, int b, int c) {
    begin = a;
    over = b;
    link = c;
  }
};
struct C {
  char tp[22];
  char ms[22];
  int cmp(char *s) { return strcmp(tp, s); }
};
queue<T> q;
int n;
char tr[22];
T ty[maxn];
C ch[maxn];
int tnum = 0;
int cnum = 0;
char tar[22];
int loc = -1;
int line = 0;
void Try() {
  ty[tnum++].begin = line;
  char c = getchar();
  while (c != '\n' && c != EOF) {
    c = getchar();
  }
  ungetc(c, stdin);
}
void Catch() {
  char c;
  if (loc < ty[tnum - 1].begin || loc > line) {
    --tnum;
    while (c != '\n' && c != EOF) {
      c = getchar();
    }
    ungetc(c, stdin);
    return;
  }
  ty[tnum - 1].link = cnum;
  ty[tnum - 1].over = line;
  q.push(ty[tnum - 1]);
  --tnum;
  getchar();
  getchar();
  getchar();
  getchar();
  getchar();
  c = getchar();
  while ((c > 'z' || c < 'a') && (c > 'Z' || c < 'A')) {
    c = getchar();
  }
  int i = 0;
  while (c != ',' && c != ' ') {
    ch[cnum].tp[i++] = c;
    c = getchar();
  }
  ch[cnum].tp[i] = '\0';
  while (c == ' ') c = getchar();
  if (c == ',') c = getchar();
  while (c == ' ') c = getchar();
  i = 0;
  if (c == '\"') c = getchar();
  while (c != '\"') {
    ch[cnum].ms[i++] = c;
    c = getchar();
  }
  ch[cnum].ms[i] = '\0';
  while (c != '\n' && c != EOF) c = getchar();
  ungetc(c, stdin);
  ++cnum;
}
void Throw() {
  loc = line;
  char c;
  getchar();
  getchar();
  getchar();
  getchar();
  getchar();
  c = getchar();
  while ((c > 'z' || c < 'a') && (c > 'Z' || c < 'A')) {
    c = getchar();
  }
  int i = 0;
  while (c != ' ' && c != ')') {
    tar[i++] = c;
    c = getchar();
  }
  tar[i] = '\0';
  while (c != '\n' && c != EOF) c = getchar();
  ungetc(c, stdin);
}
int read() {
  char c;
  c = getchar();
  while (c != EOF && c != '\n') {
    switch (c) {
      case 't':
        c = getchar();
        if (c == 'h') {
          ungetc('h', stdin);
          ungetc('t', stdin);
          Throw();
        } else {
          ungetc('r', stdin);
          ungetc('t', stdin);
          Try();
        }
        break;
      case 'c':
        ungetc(c, stdin);
        Catch();
        break;
      default:
        break;
    }
    c = getchar();
  }
  line++;
  if (c == EOF) return EOF;
  return 0;
}
int main() {
  scanf("%d\n", &n);
  while (read() != EOF)
    ;
  T work;
  while (q.size()) {
    work = q.front();
    q.pop();
    int b = work.link;
    if (ch[b].cmp(tar) == 0) {
      printf("%s\n", ch[b].ms);
      return 0;
    }
  }
  printf("Unhandled Exception\n");
  return 0;
}
