#include <bits/stdc++.h>
using namespace std;
int inSize(int c, int x, int y) {
  if (c >= x && c <= y) return true;
  return false;
}
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};
int wx[] = {0, 1, -1, 1, -1, 0, 1, -1};
int wy[] = {1, 1, 1, 0, 0, -1, -1, -1};
int tx[] = {-1, -2, -2, -1, 1, 2, 2, 1};
int ty[] = {2, 1, -1, -2, -2, -1, 1, 2};
const int maxn = 1000000;
int n, m;
char str[100001];
char ss[100001];
char thw[10001];
char sbw[10001];
char ret[10001];
int sbl;
int cnt;
bool guile;
void sbstr1(int l, int r) {
  for (int i = 0; i < r - l + 1; i++) {
    thw[i] = ss[l + i];
  }
  thw[r - l + 1] = '\0';
}
void sbstr2(int l, int r) {
  for (int i = 0; i < r - l + 1; i++) {
    sbw[i] = ss[l + i];
  }
  sbw[r - l + 1] = '\0';
}
void sbstr3(int l, int r) {
  for (int i = 0; i < r - l + 1; i++) {
    ret[i] = ss[l + i];
  }
  ret[r - l + 1] = '\0';
}
int main() {
  guile = false;
  sbl = cnt = 0;
  scanf("%d", &(n));
  gets(str);
  bool Ysb = false;
  while (n--) {
    gets(str);
    bool flag = true;
    int len = strlen(str);
    int cc = 0;
    for (int i = 0; i < len; i++) {
      if (str[i] == ' ' && flag) continue;
      if (str[i] == '"') flag = !flag;
      ss[cc++] = str[i];
    }
    ss[cc] = '\0';
    if (ss[0] == 't' && ss[1] == 'h') {
      int l, r;
      for (int i = 0; i < (int)strlen(ss); i++) {
        if (ss[i] == '(') l = i;
        if (ss[i] == ')') r = i;
      }
      sbstr1(l + 1, r - 1);
      Ysb = true;
    } else if (ss[0] == 't') {
      if (Ysb == true) sbl++;
    } else if (ss[0] == 'c') {
      if (sbl > 0) {
        sbl--;
      } else {
        int l, r;
        for (int i = 0; i < (int)strlen(ss); i++) {
          if (ss[i] == '(') l = i;
          if (ss[i] == ',') {
            r = i;
            break;
          }
        }
        sbstr2(l + 1, r - 1);
        if (!strcmp(sbw, thw)) {
          int ll = r;
          l = -1;
          for (int(i) = (ll + 1); (i) <= ((int)strlen(ss) - 1); (i)++) {
            if (l != -1 && ss[i] == '"') {
              r = i;
              break;
            }
            if (l == -1 && ss[i] == '"') l = i;
          }
          sbstr3(l + 1, r - 1);
          cout << ret << endl;
          guile = true;
          break;
        }
      }
    }
  }
  if (!guile) puts("Unhandled Exception");
}
