#include <bits/stdc++.h>
using namespace std;
vector<pair<string, string> > excp(100001);
vector<int> when(100001);
vector<bool> op(100001);
stack<int> blocks;
string input;
string targ;
string res;
void clearspaces() {
  string tmp;
  int j;
  for (j = 0; input[j] == ' '; j++) {
  }
  for (; j < input.size(); j++) tmp += input[j];
  input = tmp;
}
string fromthrow(string tmp) {
  int j;
  string cur;
  for (j = 0; tmp[j] != '('; j++) {
  }
  j++;
  for (; !(tmp[j] >= 'A' && tmp[j] <= 'Z') && !(tmp[j] >= 'a' && tmp[j] <= 'z');
       j++) {
  }
  while ((tmp[j] >= 'A' && tmp[j] <= 'Z') || (tmp[j] >= 'a' && tmp[j] <= 'z')) {
    cur += tmp[j++];
  }
  return cur;
}
pair<string, string> fromcatch(string tmp) {
  int j;
  string cur, cur2;
  for (j = 0; tmp[j] != '('; j++) {
  }
  j++;
  for (; !(tmp[j] >= 'A' && tmp[j] <= 'Z') && !(tmp[j] >= 'a' && tmp[j] <= 'z');
       j++) {
  }
  while ((tmp[j] >= 'A' && tmp[j] <= 'Z') || (tmp[j] >= 'a' && tmp[j] <= 'z')) {
    cur += tmp[j];
    j++;
  }
  for (; tmp[j - 1] != '"'; j++) {
  }
  for (; tmp[j] != '"'; j++) cur2 += tmp[j];
  return make_pair(cur, cur2);
}
int main() {
  int i, j = 0, n, m, k = 1, efl = 0;
  cin >> n;
  for (j = 1; j <= n; j++) op[j] = 0;
  while (cin) {
    j++;
    input.clear();
    getline(cin, input);
    clearspaces();
    if (input.size() == 0) continue;
    if (input[1] == 'r') {
      if (efl == 0) op[k] = 1;
      blocks.push(k);
      k++;
    }
    if (input[1] == 'h') {
      targ = fromthrow(input);
      efl = 1;
    }
    if (input[1] == 'a') {
      int num = blocks.top();
      blocks.pop();
      excp[num] = fromcatch(input);
      if (!efl) op[num] = 0;
      when[num] = j;
    }
  }
  int curwhen;
  for (j = 1; j <= n; j++) {
    if (op[j] && excp[j].first == targ &&
        (res.size() == 0 || when[j] < curwhen)) {
      res = excp[j].second;
      curwhen = when[j];
    }
  }
  if (res.size() == 0)
    cout << "Unhandled Exception" << endl;
  else
    cout << res;
}
