#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
template <class T>
T _max(T x, T y) {
  return x > y ? x : y;
}
template <class T>
T _min(T x, T y) {
  return x < y ? x : y;
}
template <class T>
T _abs(T x) {
  return (x < 0) ? -x : x;
}
template <class T>
T _mod(T x, T y) {
  return (x > 0) ? x % y : ((x % y) + y) % y;
}
template <class T>
void _swap(T& x, T& y) {
  T t = x;
  x = y;
  y = t;
}
template <class T>
void getmax(T& x, T y) {
  x = (y > x) ? y : x;
}
template <class T>
void getmin(T& x, T y) {
  x = (x < 0 || y < x) ? y : x;
}
int TS, cas = 1;
const int M = 100000 + 5;
int n;
stack<int> s;
char ex[M];
char ret[M];
char str[M];
char tmp[M];
void run() {
  int i, j;
  getchar();
  while (!s.empty()) s.pop();
  strcpy(ret, "Unhandled Exception");
  bool flag = false;
  while (n--) {
    gets(str);
    if (flag) continue;
    for (i = 0; str[i]; i++) {
      if (str[i] == 't') {
        if (str[i + 1] == 'r') {
          s.push(1);
        } else {
          s.push(10);
          for (; str[i]; i++)
            if (str[i] == '(') break;
          for (i++, j = 0; str[i]; i++) {
            if (str[i] == ')') break;
            if (isalpha(str[i])) ex[j++] = str[i];
          }
          ex[j] = 0;
        }
        break;
      } else if (str[i] == 'c') {
        if (s.top() != 10) {
          s.pop();
          break;
        }
        s.pop(), s.pop();
        s.push(10);
        for (; str[i]; i++)
          if (str[i] == '(') break;
        for (i++, j = 0; str[i]; i++) {
          if (str[i] == ',') break;
          if (isalpha(str[i])) tmp[j++] = str[i];
        }
        tmp[j] = 0;
        if (strcmp(tmp, ex) == 0) {
          flag = true;
          for (; str[i]; i++)
            if (str[i] == '"') break;
          for (i++, j = 0; str[i]; i++) {
            if (str[i] == '"') break;
            ret[j++] = str[i];
          }
          ret[j] = 0;
        }
        break;
      }
    }
  }
  puts(ret);
}
void preSof() {}
int main() {
  preSof();
  while ((~scanf("%d", &n))) run();
  return 0;
}
