#include <bits/stdc++.h>
using namespace std;
char buf[1000];
char wt[1000];
int wlen;
int main() {
  int n;
  scanf("%d", &n);
  gets(buf);
  vector<int> st;
  int found = false;
  wlen = -1;
  for (int i = (0); i < (n); ++i) {
    gets(buf);
    int len = 0;
    int rm = 1;
    for (char* c = buf; *c; ++c) {
      if (!rm || !isspace(*c)) buf[len++] = *c;
      if (*c == '"') rm = !rm;
    }
    buf[len] = 0;
    if (!len) continue;
    if (buf[1] == 'r') {
      st.push_back(wlen == -1);
      continue;
    }
    if (buf[1] == 'a') {
      int fine = st.back();
      st.pop_back();
      if (!fine) continue;
      int p = 0;
      while (buf[p] != '(') ++p;
      int p2 = ++p;
      while (buf[p2] != ',') ++p2;
      if (wlen != p2 - p) continue;
      bool ok = true;
      for (int i = (p); i < (p2); ++i)
        if (wt[i - p] != buf[i]) ok = false;
      if (!ok) continue;
      p = p2 + 2;
      p2 = p + 1;
      while (buf[p2] != '"') ++p2;
      buf[p2] = 0;
      cout << (&buf[p]) << endl;
      found = true;
      break;
    }
    int p = 0;
    while (buf[p] != '(') ++p;
    int p2 = ++p;
    while (buf[p2] != ')') ++p2;
    for (int i = (p); i < (p2); ++i) wt[i - p] = buf[i];
    wlen = p2 - p;
    wt[wlen] = 0;
  }
  if (!found) puts("Unhandled Exception");
}
