#include <bits/stdc++.h>
char str[105];
char a[105];
char b[105];
char c[105];
char s[105];
char ch[105] = {"vFkkeetHOUULrZAPLYWW,\"Q12u\""};
char cch[105] = {"GYqJhuyoTApao"};
int x, y, ans;
char ccch[105] = {"sYVewpI"};
int stricmp(char r[], char d[]) {
  if (strlen(r) != strlen(d)) return 1;
  for (int i = 0; r[i] != '\0'; i++)
    if (r[i] != d[i] && (r[i] - d[i]) != 32 && (r[i] - d[i]) != -32) return 1;
  return 0;
}
int fun(char ch1, char ch2) {
  if (ch1 != ch2 && (ch1 - ch2) != 32 && (ch1 - ch2) != -32) return 0;
  return 1;
}
int main() {
  while (gets(s) != NULL) {
    int n = 0;
    for (int i = 0; s[i] != '\0'; i++) n = n * 10 + s[i] - '0';
    int i = 0;
    int anss = 0;
    while (i < n) {
      i++;
      gets(str);
      int flag = 0;
      int j = 0;
      while (str[j] == ' ') j++;
      if (str[j] == 't' || str[j] == 'T')
        if (str[j + 1] == 'h' || str[j + 1] == 'H') {
          flag = 1;
          break;
        }
      if (flag == 1) break;
    }
    int j = 0;
    while (str[j] != '(') j++;
    j++;
    while (str[j] == ' ') j++;
    for (int k = j;; k++) {
      if (str[k] == ' ' || str[k] == ')') {
        a[k - j] = '\0';
        break;
      }
      a[k - j] = str[k];
    }
    x = 0, ans = 0;
    int ff = 0;
    while (i < n) {
      gets(str);
      j = 0;
      i++;
      while (str[j] == ' ') j++;
      if (str[j] != '\0') {
        if (str[j] == 't' || str[j] == 'T') {
          x++;
          if (str[j + 1] == 'h' || str[j + 1] == 'H') anss++;
        }
        if (str[j] == 'c' || str[j] == 'C') {
          x--;
          if (x < 0) {
            x = 0;
            while (str[j] != '(') j++;
            j++;
            while (str[j] == ' ') j++;
            for (int k = j;; k++) {
              if (str[k] == ' ' || str[k] == ',') {
                b[k - j] = '\0';
                break;
              }
              b[k - j] = str[k];
            }
            if (stricmp(a, b) == 0 && ans == 0) {
              ans = 1;
              while (str[j] != '\"') j++;
              j++;
              int h = strlen(str) - 1;
              while (str[h] != '\"') h--;
              while (j < h) printf("%c", str[j++]);
              printf("\n");
              ff = 1;
              strcpy(c, b);
            }
          }
        }
      }
    }
    if (ff == 0) printf("Unhandled Exception\n");
  }
  return 0;
}
