#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000100;
const int MAXN = 200100;
void cut(string& s) {
  if (s.size() == 0) return;
  int pocz = 0, kon = s.size() - 1;
  while (pocz < s.size() && s[pocz] == ' ') pocz++;
  while (kon >= pocz && s[kon] == ' ') kon--;
  s = s.substr(pocz, kon - pocz + 1);
}
stack<string> stos;
int n, beg;
string s;
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  getline(cin, s);
  for (int i = 1; i <= n; i++) {
    getline(cin, s);
    cut(s);
    if (s.size() == 0) continue;
    if (s == "try") {
      stos.push("");
    } else if (s.substr(0, 5) == "throw") {
      for (int i = 0; i < s.size(); i++)
        if (s[i] == '(') {
          beg = i;
          break;
        }
      for (int i = beg; i < s.size(); i++)
        if (isalpha(s[i])) {
          beg = i;
          break;
        }
      string thr = "";
      for (int i = beg; i < s.size(); i++) {
        if (!isalpha(s[i])) break;
        thr += s[i];
      }
      stos.push(thr);
    } else {
      for (int i = 0; i < s.size(); i++)
        if (s[i] == '(') {
          beg = i;
          break;
        }
      for (int i = beg; i < s.size(); i++)
        if (isalpha(s[i])) {
          beg = i;
          break;
        }
      string ex = "";
      for (int i = beg; i < s.size(); i++) {
        if (!isalpha(s[i])) break;
        ex += s[i];
        beg = i + 1;
      }
      string out = "";
      for (int i = beg; i < s.size(); i++) {
        if (s[i] == '\"') {
          beg = i + 1;
          break;
        }
      }
      for (int i = beg; i < s.size(); i++) {
        if (s[i] == '\"') break;
        out += s[i];
      }
      if (stos.top() == "")
        stos.pop();
      else {
        string thr = stos.top();
        stos.pop();
        if (thr == ex) {
          cout << out << endl;
          return 0;
        }
        stos.pop();
        stos.push(thr);
      }
    }
  }
  cout << "Unhandled Exception" << endl;
}
