#include <bits/stdc++.h>
using namespace std;
int main() {
  string word, type;
  int n;
  cin >> n;
  int j;
  int cur = 0, real = 0, sreal = 0;
  bool t = false, b = false;
  getline(cin, word);
  for (int i = 0; i < n; ++i) {
    getline(cin, word);
    for (j = 0; j < (int)word.size() && word[j] == ' '; ++j)
      ;
    if (j != word.size()) {
      if (word[j] == 'c') {
        if (t) {
          if (cur <= real) {
            for (; j < (int)word.size() && word[j] != '('; ++j)
              ;
            for (; j < (int)word.size() && word[j] == '(' || word[j] == ' ';
                 ++j)
              ;
            if (type == word.substr(j, type.size())) {
              for (; j < (int)word.size() && word[j] != '"'; ++j)
                ;
              ++j;
              for (; j < (int)word.size() && word[j] != '"'; ++j) {
                cout << word[j];
              }
              return 0;
            }
          }
          --cur;
          if (b) {
            if (sreal) {
              --sreal;
            } else {
              --real;
            }
          }
        }
      }
      if (word[j] == 't' && word[j + 1] == 'r') {
        ++cur;
        if (b) {
          ++sreal;
        }
      }
      if (word[j] == 't' && word[j + 1] == 'h') {
        t = true;
        b = true;
        for (; j < word.size() && word[j] != '('; ++j)
          ;
        for (; j < word.size() && word[j] == '(' || word[j] == ' '; ++j)
          ;
        for (; j < word.size() && word[j] != ' ' && word[j] != ')'; ++j) {
          type.push_back(word[j]);
        }
        real = cur;
      }
    }
  }
  cout << "Unhandled Exception";
  return 0;
}
