#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  char c[51];
  string s;
  int ind;
  bool end;
  bool success = false;
  string ex;
  int exDeep = -1;
  int deep = 0;
  int ind2;
  string message = "Unhandled Exception";
  cin.getline(c, 51);
  for (int i = 0; i < n; i++) {
    cin.getline(c, 51);
    if (success) continue;
    s = string(c);
    end = true;
    for (int j = 0; j < s.size(); j++) {
      if (s[j] != ' ') {
        ind = j;
        end = false;
        break;
      }
    }
    if (end) continue;
    if (s[ind] == 't') {
      if (s[ind + 1] == 'r') {
        deep++;
        continue;
      } else {
        ind = s.find('(', ind);
        ind++;
        while (s[ind] == ' ') ind++;
        ind2 = s.find(')', ind);
        while (s[ind2 - 1] == ' ') ind2--;
        ex = s.substr(ind, ind2 - ind);
        exDeep = deep;
      }
      continue;
    }
    if (exDeep == -1) {
      deep--;
      continue;
    };
    if (deep > exDeep) {
      deep--;
      continue;
    };
    ind = s.find('(', ind);
    ind++;
    while (s[ind] == ' ') ind++;
    ind2 = s.find(',', ind);
    while (s[ind2 - 1] == ' ') ind2--;
    string type = s.substr(ind, ind2 - ind);
    if (ex != type) {
      deep--;
      exDeep--;
      continue;
    };
    ind = s.find('\"', ind2);
    ind2 = s.find('\"', ind + 1);
    message = s.substr(ind + 1, ind2 - ind - 1);
    success = true;
  }
  cout << message;
  return 0;
}
