#include <bits/stdc++.h>
using namespace std;
const long long LINF = 1e18 + 7;
const int N = 1e5 + 7;
const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0);
const double EPS = 1e-8;
struct Node {
  string ope, exc, msg;
  Node() {}
  Node(string o, string e, string m) { ope = o, exc = e, msg = m; }
  void out() { cout << ope << ", " << exc << ", " << msg << endl; }
} EXC;
void trim(string &str) {
  str.erase(0, str.find_first_not_of(' '));
  str.erase(str.find_last_not_of(' ') + 1);
}
string get(const string &str, char start, char end) {
  stringstream ss;
  bool flag = false;
  for (int i = (0); i < (str.length()); ++i)
    if (flag) {
      if (str[i] == end) break;
      ss << str[i];
    } else if (str[i] == start) {
      flag = true;
    }
  string ret = ss.str();
  trim(ret);
  return ret;
}
Node gao(const string &str) {
  if (str[1] == 'r') return Node("try", "", "");
  if (str[1] == 'h') {
    string e = get(str, '(', ')');
    return Node("throw", e, "");
  }
  if (str[1] == 'a') {
    string e = get(str, '(', ',');
    string m = get(str, '"', '"');
    return Node("catch", e, m);
  }
}
int pos, top, sta[N];
string solve(int n) {
  string str, ans = "Unhandled Exception";
  top = 0, pos = -1;
  for (int i = (0); i < (n); ++i) {
    getline(cin, str);
    trim(str);
    if (~str.find("try") || ~str.find("catch") || ~str.find("throw")) {
      Node nd = gao(str);
      if (nd.ope == "try") {
        sta[++top] = i;
      } else if (nd.ope == "catch") {
        if (top > 0 && ~pos && sta[top] < pos && nd.exc == EXC.exc) {
          ans = nd.msg;
          break;
        }
        --top;
      } else if (nd.ope == "throw") {
        pos = i, EXC = nd;
      }
    }
  }
  return ans;
}
int main() {
  int n;
  cin >> n;
  string ans = solve(n + 1);
  cout << ans << endl;
  return 0;
}
