#include <bits/stdc++.h>
using namespace std;
int st[100100];
char s1[100];
string s;
string res, msg;
vector<string> a;
int main() {
  int isres = 0;
  res = "Unhandled Exception";
  int top = 0;
  int lt = -1;
  int n1;
  cin >> n1;
  gets(s1);
  for (int it = (0); it < (n1); ++it) {
    gets(s1);
    s = "";
    int n = strlen(s1);
    int cnt = 0;
    for (int i = (0); i < (n); ++i) {
      if (s1[i] == '"') cnt++;
      if ((s1[i] == '(') || (s1[i] == ')') || (s1[i] == '"') ||
          (s1[i] == ',')) {
        s += ' ';
        s += s1[i];
        s += ' ';
      } else {
        if ((cnt == 1) && (s1[i] == ' '))
          s += '_';
        else
          s += s1[i];
      }
    }
    a.clear();
    stringstream tmp;
    tmp << s;
    while (tmp >> s) a.push_back(s);
    if (a.size() == 0) continue;
    if (a[0] == "try") {
      st[top] = it;
      top++;
    } else {
      if (a[0] == "throw") {
        msg = a[2];
        lt = it;
      } else {
        string s2 = a[2];
        if ((isres == 0) && (s2 == msg) && (st[top - 1] < lt)) {
          isres = 1;
          res = a[5];
        }
        top--;
      }
    }
  }
  for (int i = (0); i < (res.size()); ++i)
    if (res[i] == '_') res[i] = ' ';
  cout << res << endl;
  return 0;
}
