#include <bits/stdc++.h>
using namespace std;
struct node {
  int pos1;
  int pos2;
  string a;
  string b;
};
stack<int> tryy;
vector<node> catchh;
string throww = "";
int idx;
bool cmp(node x, node y) { return x.pos1 < y.pos1; }
int main() {
  int n;
  cin >> n;
  getchar();
  for (int i = 1; i <= n; ++i) {
    string s;
    getline(cin, s);
    int len = s.length();
    for (int j = 0; j < len; ++j) {
      if (s[j] == ' ') continue;
      if (s[j] == 't') {
        if (s[j + 1] == 'r') {
          tryy.push(i);
        } else {
          int k = j + 1;
          for (; k < len; ++k) {
            if (s[k] == '(') break;
          }
          ++k;
          for (; k < len; ++k) {
            if (s[k] != ' ') break;
          }
          for (; k < len; ++k) {
            if (s[k] == ' ' || s[k] == ')') break;
            throww = throww + s[k];
          }
          idx = i;
        }
        break;
      }
      if (s[j] == 'c') {
        string aa = "";
        int k = j + 1;
        for (; k < len; ++k) {
          if (s[k] == '(') break;
        }
        ++k;
        for (; k < len; ++k) {
          if (s[k] != ' ') break;
        }
        for (; k < len; ++k) {
          if (s[k] == ' ' || s[k] == ',') break;
          aa = aa + s[k];
        }
        string bb = "";
        for (; k < len; ++k) {
          if (s[k] == '\"') break;
        }
        ++k;
        for (; k < len; ++k) {
          if (s[k] == '\"') break;
          bb = bb + s[k];
        }
        int pos1 = tryy.top();
        tryy.pop();
        catchh.push_back({pos1, i, aa, bb});
        break;
      }
    }
  }
  sort(catchh.begin(), catchh.end(), cmp);
  int siz = catchh.size();
  bool f = 0;
  for (int i = siz - 1; i >= 0; --i) {
    if (f) break;
    node tmp = catchh[i];
    if (tmp.pos1 < idx && tmp.pos2 > idx) {
      if (tmp.a == throww) {
        cout << tmp.b;
        f = 1;
        break;
      }
    }
  }
  if (!f) {
    cout << "Unhandled Exception";
  }
  return 0;
}
