#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  string c = "", res = "";
  int lt = 0, cnt = 0;
  for (int i = 0; i < n + 1; i++) {
    string s;
    getline(cin, s);
    int ind = 0;
    while (s[ind] == ' ') {
      ind++;
    }
    if (ind == s.size()) {
      continue;
    }
    string str = s.substr(ind, 3);
    string cur = "", curo = "";
    if (str == "try") {
      if (lt != 0) {
        cnt++;
      }
    } else if (str == "thr") {
      lt = 1;
      ind += 5;
      while (s[ind] == ' ' || s[ind] == '(') {
        ind++;
      }
      while (s[ind] != ' ' && s[ind] != ')') {
        c += s[ind];
        ind++;
      }
    } else {
      if (cnt != 0) {
        cnt--;
        continue;
      }
      ind += 5;
      if (c == "") {
        continue;
      } else {
        while (s[ind] == ' ' || s[ind] == '(') {
          ind++;
        }
        while (s[ind] != ' ' && s[ind] != ',') {
          cur += s[ind];
          ind++;
        }
        while (s[ind] == ' ' || s[ind] == ',' || s[ind] == '"') {
          ind++;
        }
        while (s[ind] != '"') {
          curo += s[ind];
          ind++;
        }
      }
      if (c == cur) {
        cout << curo << endl;
        return 0;
      }
    }
  }
  cout << "Unhandled Exception" << endl;
  return 0;
}
