#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long inf = 1e18 + 5;
const long long MX = 303030;
int cox[4] = {1, -1, 0, 0};
int coy[4] = {0, 0, 1, -1};
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
long long leastbit(long long a) { return a & (-a); }
long long C(int a, int b) {
  long long res = 1;
  for (int i = 0; i < b; i++) res = res * (a - i) / (i + 1);
  return res;
}
long long powmod(long long a, long long b) {
  if (b == 0) return 1;
  long long cnt = powmod(a, b / 2);
  (cnt *= cnt) %= mod;
  if (b & 1) {
    (cnt *= a) %= mod;
  }
  return cnt;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  int t, i, bad = 0, cnt = 0, flag = 0;
  string s, tmp = "***", ans;
  cin >> t;
  cin.ignore();
  while (t--) {
    getline(cin, s);
    i = 0;
    while (i < s.length() &&
           (s[i] == ' ' || s[i] == '(' || s[i] == ')' || s[i] == '\"'))
      i++;
    if (tmp != "***") {
      if (s[i] == 't') {
        cnt++;
        continue;
      }
      if (s[i] == 'c')
        if (cnt) {
          cnt--;
          continue;
        }
    }
    if (i < s.length() && s[i] == 't' && s[i + 1] == 'r')
      continue;
    else if (s.size() && s[i] == 'c') {
      i += 5;
      string bs, ans;
      while (i < s.length() &&
             (s[i] == ' ' || s[i] == '(' || s[i] == ')' || s[i] == '\"'))
        i++;
      while (s[i] != ',') bs.push_back(s[i]), i++;
      i++;
      while (bs.size() && bs.back() == ' ') bs.pop_back();
      while (i < s.length() &&
             (s[i] == ' ' || s[i] == '(' || s[i] == ')' || s[i] == '\"'))
        i++;
      while (s[i] != '\"') ans.push_back(s[i]), i++;
      while (ans.back() == ' ') ans.pop_back();
      if (bs == tmp) {
        cout << ans << endl;
        return 0;
      }
    } else if (s.size() && s[i] == 't') {
      i += 5;
      string bs;
      while (i < s.length() &&
             (s[i] == ' ' || s[i] == '(' || s[i] == ')' || s[i] == '\"'))
        i++;
      while (s[i] != ')') bs.push_back(s[i]), i++;
      while (bs.back() == ' ') bs.pop_back();
      tmp = bs;
    }
  }
  cout << "Unhandled Exception" << endl;
  return 0;
}
