#include <bits/stdc++.h>
using namespace std;
int main() {
  string buffer;
  vector<string> cpp;
  getline(cin, buffer);
  while (getline(cin, buffer)) {
    if (buffer.size() == 0) continue;
    while (buffer.size() && buffer.back() == ' ') buffer.pop_back();
    reverse(buffer.begin(), buffer.end());
    while (buffer.size() && buffer.back() == ' ') buffer.pop_back();
    reverse(buffer.begin(), buffer.end());
    if (buffer.size() == 0) continue;
    cpp.push_back(buffer);
  }
  vector<list<string>> stk;
  stk.push_back(list<string>());
  stk.push_back(list<string>());
  bool ok = false;
  for (string& s : cpp) {
    if (s == "try") {
      stk.push_back(list<string>());
    } else if (s[0] == 't') {
      int i = s.find('('), j = s.find(')');
      auto str = s.c_str();
      string name(str + i + 1, str + j);
      name.erase(copy_if(name.begin(), name.end(), name.begin(),
                         [](const char ch) { return ch != ' '; }),
                 name.end());
      stk.back().push_back(name);
    } else {
      int i = s.find('('), j = s.find(',');
      auto str = s.c_str();
      string key(str + i + 1, str + j);
      key.erase(copy_if(key.begin(), key.end(), key.begin(),
                        [](const char ch) { return ch != ' '; }),
                key.end());
      i = 0, j = s.size() - 1;
      while (s[i] != '"') i++;
      while (s[j] != '"') j--;
      string inf(str + i + 1, str + j);
      auto it = stk.back().begin();
      while (it != stk.back().end()) {
        if (*it == key) {
          cout << inf << endl;
          stk.back().clear();
          ok = true;
          goto Break;
        }
        it++;
      }
      stk.end()[-2].splice(stk.end()[-2].end(), stk.back());
      stk.pop_back();
    }
  }
Break:
  if (!ok) cout << "Unhandled Exception" << endl;
  return 0;
}
