#include <bits/stdc++.h>
using namespace std;
char c[100];
int main() {
  int n;
  cin >> n;
  int i;
  cin.getline(c, 100);
  int open = 0;
  string tt = "";
  for (i = 0; i < n; i++) {
    cin.getline(c, 100);
    string s = "";
    int k = strlen(c);
    int j = 0, z;
    while (j < k && (c[j] == ' ' || c[j] == '\t')) j++;
    z = k - 1;
    while (z >= j && (c[z] == ' ' || c[z] == '\t')) z--;
    for (; j <= z; j++) {
      s += c[j];
    }
    if (s == "try") {
      open++;
    }
    if (s.substr(0, 5) == "throw") {
      open = 0;
      k = s.length();
      j = 5;
      while (j < k && (s[j] == '(' || s[j] == ' ' || s[j] == '\t')) j++;
      z = k - 1;
      while (z >= j && (s[z] == ')' || s[z] == ' ' || s[z] == '\t')) z--;
      for (; j <= z; j++) {
        tt += s[j];
      }
    }
    if (s.substr(0, 5) == "catch") {
      if (open == 0 && tt != "") {
        j = 5;
        k = s.length();
        while (j < k && (s[j] == '(' || s[j] == ' ')) j++;
        string ss = "";
        string out = "";
        for (;; j++) {
          if (s[j] == ' ' || s[j] == ',') break;
          ss += s[j];
        }
        while (j < k && s[j] != '"') j++;
        for (j++; s[j] != '"'; j++) {
          out += s[j];
        }
        if (ss == tt) {
          printf("%s\n", out.c_str());
          tt = "";
        }
      }
      open--;
      if (open < 0) open = 0;
    }
  }
  if (tt != "") {
    printf("Unhandled Exception\n");
  }
  return 0;
}
