#include <bits/stdc++.h>
using namespace std;
int n, ls, tp, cx, yy, qq;
char s[64];
string ans, cur, st[55555][2], tt;
bool quot, found;
int main() {
  scanf("%d\n", &n);
  tp = -1;
  found = false;
  qq = 0;
  for (int _ = 0; _ < n; ++_) {
    gets(s);
    ls = strlen(s);
    quot = false;
    cur = "";
    for (int i = 0; i < ls; ++i)
      if (quot) {
        if (s[i] == '"')
          quot = false;
        else
          cur += s[i];
      } else {
        if (s[i] == '"')
          quot = true;
        else if (s[i] != ' ')
          cur += s[i];
      }
    if (!cur.find("try")) {
      tp += !found;
      qq += found;
    } else if (!cur.find("catch")) {
      if (qq) {
        --qq;
        continue;
      }
      if (found) {
        st[tp][0] = "";
        cx = 6;
        while (cur[cx] != ',') st[tp][0] += cur[cx++];
        ++cx;
        st[tp][1] = "";
        while (cur[cx] != ')') st[tp][1] += cur[cx++];
        if (!tp) break;
      }
      --tp;
    } else if (!cur.find("throw")) {
      found = true;
      yy = tp;
      cx = 6;
      tt = "";
      while (cur[cx] != ')') tt += cur[cx++];
    }
  }
  ans = "Unhandled Exception";
  for (int i = yy; i >= 0; --i)
    if (st[i][0] == tt) {
      ans = st[i][1];
      break;
    }
  printf("%s", ans.c_str());
  return 0;
}
