#include <bits/stdc++.h>
using namespace std;
struct point {
  int tp;
  string s1, s2;
} a[200000];
struct node {
  int n, next;
} b[200000];
int n, l, st[200000];
map<string, int> p;
int main() {
  cin >> n;
  scanf("\n");
  int m = 0;
  for (int i = 0; i < n; i++) {
    string s;
    getline(cin, s);
    bool y = false;
    string cd = "";
    for (int j = 0; j < s.length(); j++) {
      if (s[j] == ' ' && !y) continue;
      cd += s[j];
      if (s[j] == '"') y = !y;
    }
    if (cd.length() == 0) {
      a[i].tp = -1;
      continue;
    }
    if (cd[1] == 'r') {
      a[i].tp = 0;
      st[++m] = i;
    } else if (cd[1] == 'h') {
      a[i].tp = 1;
      int j = 6;
      a[i].s1 = "";
      while (cd[j] != ')') a[i].s1 += cd[j++];
    } else {
      a[i].tp = 2;
      int j = 6;
      a[i].s1 = "";
      while (cd[j] != ',') a[i].s1 += cd[j++];
      j += 2;
      a[i].s2 = "";
      while (cd[j] != '"') a[i].s2 += cd[j++];
      a[st[m]].s2 = a[i].s2;
      a[st[m--]].s1 = a[i].s1;
    }
  }
  l = 1;
  for (int i = 0; i < n; i++)
    if (a[i].tp != -1) {
      if (a[i].tp == 0) {
        l++;
        b[l].n = i;
        if (p.count(a[i].s1) > 0) {
          b[l].next = p[a[i].s1];
          p[a[i].s1] = l;
        } else {
          b[l].next = 0;
          p[a[i].s1] = l;
        }
      } else if (a[i].tp == 1) {
        if (p.count(a[i].s1)) {
          if (p[a[i].s1] != 0) {
            cout << a[b[p[a[i].s1]].n].s2;
            return 0;
          }
        }
      } else if (a[i].tp == 2) {
        if (p.count(a[i].s1)) {
          p[a[i].s1] = b[p[a[i].s1]].next;
        }
      }
    }
  cout << "Unhandled Exception";
}
