#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, ind = 0, ct = 0, flag = 0;
  char x;
  scanf("%d", &n);
  scanf("%c", &x);
  vector<int> a;
  string exception, message, checkexception;
  for (int i = 0; i < n; i++) {
    scanf("%c", &x);
    while (x != '\n') {
      if (x == 't') {
        scanf("%c", &x);
        if (x == 'r') {
          a.push_back(1);
          while (x != '\n') {
            scanf("%c", &x);
          }
        } else if (x == 'h') {
          while (x != '\n') {
            scanf("%c", &x);
            if (x == '(') {
              while (x != ')') {
                scanf("%c", &x);
                if (x != ' ' && x != ')') {
                  exception.push_back(x);
                }
              }
            }
          }
          a.push_back(-1);
        }
      } else if (x == 'c') {
        while (x != '\n') {
          scanf("%c", &x);
          if (x == '(') {
            while (x != ',') {
              scanf("%c", &x);
              if (x != ' ' && x != ',') {
                checkexception.push_back(x);
              }
            }
          }
          if (x == '"') {
            scanf("%c", &x);
            message.push_back(x);
            while (x != '"') {
              scanf("%c", &x);
              if (x != '"') message.push_back(x);
            }
          }
        }
        if (a[a.size() - 1] == -1) {
          if (exception == checkexception) {
            cout << message << endl;
            a.pop_back();
            flag = 1;
          } else
            a.erase(a.end() - 2);
        } else {
          a.pop_back();
        }
        message.clear();
        checkexception.clear();
      } else {
        scanf("%c", &x);
      }
    }
  }
  if (!flag) cout << "Unhandled Exception\n";
  return 0;
}
