#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int f = 0, num;
  char ch;
  while (ch = getchar(), !isdigit(ch))
    if (ch == '-') f = 1;
  num = ch - '0';
  while (ch = getchar(), isdigit(ch)) num = num * 10 + ch - '0';
  return f ? -num : num;
}
const int N = 103;
char s[N], ans[N], tmp[103];
char ch;
void is() {
  ch = getchar();
  while (ch != '\n') ch = getchar();
}
int cnt, tot, T, f;
int main() {
  T = read();
  f = 0, cnt = 0;
  while (T--) {
    int f1 = 0;
    tot = 0;
    ch = getchar();
    while (ch != '\n') {
      if (ch == '"') f1 = 1;
      if (f1)
        s[tot++] = ch;
      else if (ch != ' ')
        s[tot++] = ch;
      ch = getchar();
    }
    s[tot++] = '\0';
    if (f) {
      if (s[1] == 'r') cnt++;
      if (s[0] == 'c') {
        if (cnt)
          cnt--;
        else {
          tot = 0;
          int i = 6;
          while (s[i] != ',') {
            tmp[tot++] = s[i];
            i++;
          }
          tmp[tot++] = '\0';
          if (!strcmp(tmp, ans)) {
            int i = 7 + tot;
            while (s[i] != '"') {
              cout << s[i];
              i++;
            }
            cout << endl;
            f = 0;
          }
        }
      }
    }
    if (s[1] == 'h') {
      f = 1;
      tot = 0;
      for (int i = 6; s[i] != ')'; i++) ans[tot++] = s[i];
      ans[tot++] = '\0';
    }
  }
  if (f) cout << "Unhandled Exception" << endl;
  return 0;
}
