#include <bits/stdc++.h>
using namespace std;
int n;
char op[1000];
char throwType[1000];
char catchType[1000], catchMsg[1000];
string trim(string str) {
  string ret = "";
  for (int(i) = (0), _n = (str.length() - 1); (i) <= _n; (i)++)
    if (str[i] != ' ') ret += str[i];
  return ret;
}
int main() {
  scanf("%d", &n);
  gets(op);
  bool hasAns = false;
  int num = 0;
  int num2 = 0;
  string ttype;
  char* p;
  bool b = false;
  while (n--) {
    gets(op);
    p = strstr(op, "(");
    char* posThrow = (strstr(op, "throw"));
    char* posTry = strstr(op, "try");
    char* posCatch = (strstr(op, "catch"));
    int posT = (posThrow == NULL) ? 200000000 : posThrow - op;
    int posT2 = (posTry == NULL) ? 200000000 : posTry - op;
    int posC = (posCatch == NULL) ? 200000000 : posCatch - op;
    int mins = min(min(posT, posT2), posC);
    bool hasThrow = (posT == mins && posT != 200000000),
         hasTry = (posT2 == mins && posT2 != 200000000),
         hasCatch = (posC == mins && posC != 200000000);
    if (hasThrow) {
      sscanf(p, "(%[^)])", throwType);
      hasAns = true;
      ttype = trim(throwType);
    } else if (hasTry) {
      if (!hasAns)
        num++;
      else
        num2++;
    } else if (hasCatch) {
      if (hasAns) {
        if (num2 > 0)
          num2--;
        else if (p != NULL) {
          sscanf(p, "(%[^,]", catchType);
          p = strstr(op, "\"");
          sscanf(p, "\"%[^\"]", catchMsg);
          string ctype = trim(catchType);
          if (ctype == ttype) {
            printf("%s", catchMsg);
            hasAns = false;
            b = true;
          } else
            num--;
        }
      }
    }
  }
  if (!b) puts("Unhandled Exception");
  return 0;
}
