#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void smin(T &a, U b) {
  if (a > b) a = b;
}
template <typename T, typename U>
inline void smax(T &a, U b) {
  if (a < b) a = b;
}
int power(int a, int b, int m, int ans = 1) {
  for (; b; b >>= 1, a = 1LL * a * a % m)
    if (b & 1) ans = 1LL * ans * a % m;
  return ans;
}
char s[111], cmp[111];
map<string, vector<int> > mp;
stack<int> st;
int main() {
  int n;
  scanf("%d\n", &n);
  for (int i = 0; i < n; i++) {
    gets(s);
    int nn = strlen(s);
    for (int j = 0; j < nn;) {
      if (s[j] == ' ') {
        j++;
        continue;
      }
      if (strncmp(s + j, "try", 3) == 0) {
        j += 3;
        st.push(i);
        break;
      }
      if (strncmp(s + j, "throw", 5) == 0) {
        j += 5;
        while (!isalpha(s[j])) j++;
        int cnt = 0;
        while (isalpha(s[j])) cmp[cnt++] = s[j++];
        cmp[cnt] = 0;
        mp[cmp].push_back(i);
        while (!isalpha(s[j])) j++;
        break;
      }
      if (strncmp(s + j, "catch", 5) == 0) {
        j += 5;
        while (!isalpha(s[j])) j++;
        int cnt = 0;
        while (isalpha(s[j])) cmp[cnt++] = s[j++];
        cmp[cnt] = 0;
        int id = st.top();
        st.pop();
        vector<int> tmp = mp[cmp];
        if (tmp.size() == 0) break;
        id = lower_bound(tmp.begin(), tmp.end(), id) - tmp.begin();
        if (id == tmp.size()) break;
        if (tmp[id] < i) {
          while (s[j] != '"') j++;
          j++;
          cnt = 0;
          while (s[j] != '"') cmp[cnt++] = s[j++];
          cmp[cnt] = 0;
          puts(cmp);
          return 0;
        }
      }
    }
  }
  puts("Unhandled Exception");
  return 0;
}
