#include <bits/stdc++.h>
using namespace std;
int main() {
  char str[100] = {0}, ans_str[100] = {0}, tmp[100] = {0}, ch;
  int cnt = 0, k, T;
  bool flag = 0, key;
  cin >> T;
  ch = getchar();
  while (ch != '\n') ch = getchar();
  while (T--) {
    key = 0;
    k = 0;
    ch = getchar();
    while (ch != '\n') {
      if (ch == '"') key = 1;
      if (key)
        str[k++] = ch;
      else if (ch != ' ')
        str[k++] = ch;
      ch = getchar();
    }
    str[k++] = '\0';
    if (flag) {
      if (str[1] == 'r') cnt++;
      if (str[0] == 'c') {
        if (cnt)
          cnt--;
        else {
          k = 0;
          for (int i = 6; str[i] != ','; i++) tmp[k++] = str[i];
          tmp[k++] = '\0';
          if (!strcmp(tmp, ans_str)) {
            for (int i = 6 + k + 1; str[i] != '"'; i++) cout << str[i];
            cout << endl;
            flag = 0;
          }
        }
      }
    }
    if (str[1] == 'h') {
      flag = 1;
      k = 0;
      for (int i = 6; str[i] != ')'; i++) ans_str[k++] = str[i];
      ans_str[k++] = '\0';
    }
  }
  if (flag) cout << "Unhandled Exception" << endl;
  return 0;
}
