#include <bits/stdc++.h>
using namespace std;
string getExp(string s) {
  string t = "";
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '(') {
      ++i;
      while (s[i] != ')' && s[i] != ',') {
        if (s[i] != ' ') t.push_back(s[i]);
        ++i;
      }
      break;
    }
  }
  return t;
}
string getMsg(string s) {
  string t = "";
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '\"') {
      ++i;
      while (s[i] != '\"') {
        t.push_back(s[i]);
        ++i;
      }
      break;
    }
  }
  return t;
}
int main() {
  string s[100005];
  int n;
  cin >> n;
  cin.ignore();
  int expIdx;
  string myExp;
  stack<int> stk;
  int endd[100005];
  for (int i = 0; i < n; i++) {
    getline(cin, s[i]);
    if (s[i].find("throw") != std::string::npos) {
      expIdx = i;
      myExp = getExp(s[i]);
    } else if (s[i].find("catch") != string::npos) {
      endd[stk.top()] = i;
      stk.pop();
    } else if (s[i].find("try") != string::npos) {
      stk.push(i);
    }
  }
  int myMsgIdx = -1;
  for (int i = 0; i < expIdx; i++) {
    if (s[i].find("catch") == string::npos &&
        s[i].find("try") != string::npos && endd[i] > expIdx &&
        getExp(s[endd[i]]) == myExp) {
      myMsgIdx = endd[i];
    }
  }
  if (myMsgIdx == -1) {
    cout << "Unhandled Exception" << endl;
  } else {
    cout << getMsg(s[myMsgIdx]) << endl;
  }
  return 0;
}
