#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  string s;
  int j, b = 0, l;
  string e, t;
  vector<int> z;
  cin >> n;
  getline(cin, s, '\n');
  for (int i = 0; i < n; ++i) {
    getline(cin, s, '\n');
    j = 0;
    while (j < (int)s.size() && !isalpha(s[j])) ++j;
    if (j == (int)s.size()) continue;
    if (s[j] == 'c') {
      if (b > l) {
        --b;
        continue;
      }
      j += 5;
      while (!isalpha(s[j])) ++j;
      t.clear();
      while (isalpha(s[j])) {
        t += s[j];
        ++j;
      }
      if (t == e) {
        while (s[j] != '"') ++j;
        ++j;
        while (s[j] != '"') {
          cout << s[j];
          ++j;
        }
        return 0;
      } else {
        --b;
        --l;
      }
    } else if (s[j + 1] == 'r')
      ++b;
    else if (s[j + 1] == 'h') {
      j += 5;
      while (!isalpha(s[j])) ++j;
      while (isalpha(s[j])) {
        e += s[j];
        ++j;
      }
      l = b;
    } else
      ;
  }
  cout << "Unhandled Exception";
  return 0;
}
