#include <bits/stdc++.h>
using namespace std;
vector<string> lines;
int head = 0;
string trim(string s) {
  for (register int i = (0); i < (int)(((int)(s).size())); ++i)
    if (s[i] != ' ') {
      int pos = ((int)(s).size());
      while (pos > 0 && s[pos - 1] == ' ') pos--;
      string res = "";
      for (register int j = (i); j < (int)(pos); ++j) res += s[j];
      return res;
    }
  return "";
}
string parse() {
  string cur = lines[head++];
  if (cur == "try") {
    string out = "";
    while (lines[head][0] != 'c') {
      string tmp = parse();
      if (((int)(tmp).size()) > ((int)(out).size())) out = tmp;
    }
    string ex = "";
    cur = lines[head++];
    bool ok = false;
    for (register int i = (0); i < (int)(((int)(cur).size())); ++i)
      if (cur[i] == '(')
        ok = true;
      else if (cur[i] == ',')
        ok = false;
      else if (ok && cur[i] != ' ')
        ex += cur[i];
    ok = false;
    string pr = "";
    for (register int i = (0); i < (int)(((int)(cur).size())); ++i)
      if (cur[i] == '"')
        ok = !ok;
      else if (ok)
        pr += cur[i];
    if (ex == out) {
      cout << pr << endl;
      exit(0);
    }
    return out;
  } else if (cur[0] == 't' && cur[1] == 'h') {
    string tmp = "";
    bool ok = false;
    for (register int i = (0); i < (int)(((int)(cur).size())); ++i) {
      if (cur[i] == '(')
        ok = true;
      else if (cur[i] == ')')
        ok = false;
      else if (ok && cur[i] != ' ')
        tmp += cur[i];
    }
    return tmp;
  }
  return "";
}
int main() {
  int n;
  cin >> n;
  while (cin.get() != '\n')
    ;
  string tmp;
  while (n--) {
    getline(cin, tmp);
    tmp = trim(tmp);
    if (tmp != "") lines.push_back(tmp);
  }
  while (head < ((int)(lines).size()))
    if (!parse().empty()) {
      cout << "Unhandled Exception" << endl;
      return 0;
    }
  return 0;
}
