#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, j, l;
  scanf("%d", &n);
  getchar();
  string st, su, sv, svm;
  map<string, string> m;
  int fgh = 0;
  int flag = 0;
  char a[100005][55];
  for (i = 0; i < n; i++) {
    gets(a[i]);
    l = strlen(a[i]);
    j = 0;
    while (j < l && flag == 0) {
      while (j < l && a[i][j] <= 32) {
        j++;
      }
      st = "";
      while (((a[i][j] >= 97 && a[i][j] <= 122) ||
              (a[i][j] >= 65 && a[i][j] <= 90))) {
        st += a[i][j++];
      }
      if (st == "throw" && su == "") {
        m.clear();
        while (a[i][j] != '(') {
          j++;
        }
        j++;
        while (a[i][j] <= 32) {
          j++;
        }
        while (((a[i][j] >= 97 && a[i][j] <= 122) ||
                (a[i][j] >= 65 && a[i][j] <= 90))) {
          su += a[i][j++];
        }
        break;
      } else if (st == "catch" && fgh > 0) {
        fgh--;
      } else if (st == "catch" && fgh == 0) {
        while (a[i][j] != '(') {
          j++;
        }
        j++;
        while (a[i][j] <= 32) {
          j++;
        }
        sv = "";
        while (((a[i][j] >= 97 && a[i][j] <= 122) ||
                (a[i][j] >= 65 && a[i][j] <= 90))) {
          sv += a[i][j++];
        }
        while (a[i][j] != '"') {
          j++;
        }
        j++;
        svm = "";
        while (a[i][j] != '"') {
          svm += a[i][j++];
        }
        if (sv == su) {
          cout << svm << endl;
          flag = 1;
          break;
        }
        m.insert(pair<string, string>(sv, svm));
        break;
      } else if (st == "try" && su != "") {
        m.clear();
        fgh++;
        break;
      } else {
        break;
      }
    }
  }
  if (flag == 0) {
    cout << "Unhandled Exception" << endl;
  }
  return 0;
}
