#include <bits/stdc++.h>
using namespace std;
char str[60], tmp[60];
string s;
string type, message;
string format(char *str) {
  int len = strlen(str);
  int j = 0;
  for (int i = 0; i < len; i++) {
    if (str[i] != ' ') {
      tmp[j++] = str[i];
    }
  }
  tmp[j] = 0;
  return string(tmp);
}
string getType(string &s) {
  string ret = "";
  for (int i = 6; i < s.length(); i++) {
    if (s[i] == ',') {
      break;
    } else {
      ret.push_back(s[i]);
    }
  }
  return ret;
}
string getMessage(char *str) {
  int len = strlen(str);
  string ret = "";
  int cnt = 0;
  for (int i = 6; i < len; i++) {
    if (str[i] == '"') {
      cnt++;
      if (cnt == 1) {
        ret = "";
      } else {
        break;
      }
    } else {
      ret.push_back(str[i]);
    }
  }
  return ret;
}
int main() {
  int n;
  scanf("%d", &n);
  getchar();
  stack<string> stk;
  stk.push("");
  while (n--) {
    gets(str);
    s = format(str);
    if (s == "") {
      continue;
    }
    if (s[1] == 'h') {
      stk.top() = s.substr(6, s.length() - 7);
    } else if (s[1] == 'r') {
      stk.push("");
    } else if (s[1] == 'a') {
      type = getType(s);
      message = getMessage(str);
      if (type == stk.top()) {
        printf("%s\n", message.c_str());
        stk.top() = "";
      }
      if (stk.top() != "") {
        string tt = stk.top();
        stk.pop();
        stk.top() = tt;
      } else {
        stk.pop();
      }
    }
  }
  if (stk.top() != "") {
    puts("Unhandled Exception");
  }
  return 0;
}
