#include <bits/stdc++.h>
using namespace std;
const int T = 100003;
int typ[T], st;
struct A {
  char a[30], b[30];
} sb[T];
char str[250], tga[30];
stack<int> s;
void suc(int i) { printf("%s", sb[i].b); }
int main() {
  int n, tot(0);
  scanf("%d", &n);
  getchar();
  for (int i = 1; i <= n - tot; i++) {
    gets(str);
    int j(0);
    bool ok(0);
    for (; str[j] && !ok; j++)
      if (isalpha(str[j])) ok = 1;
    if (!ok) {
      i--, tot++;
      continue;
    }
    j = 0;
    while (str[j] == ' ') j++;
    if (str[j] == 't' && str[j + 1] == 'r') {
      typ[i] = 1;
      continue;
    }
    if (str[j] == 't' && str[j + 1] == 'h') {
      typ[i] = 521, st = i;
      for (j = 0; str[j] != '('; j++)
        ;
      for (j += 1; str[j] == ' '; j++)
        ;
      int k(j);
      for (; isdigit(str[k]) || isalpha(str[k]); k++)
        ;
      k -= 1;
      memcpy(tga, str + j, sizeof(char) * (k - j + 1));
      continue;
    }
    typ[i] = 2;
    for (j = 0; str[j] != '('; j++)
      ;
    for (j += 1; str[j] == ' '; j++)
      ;
    int k(j);
    for (; isalpha(str[k]) || isdigit(str[k]); k++)
      ;
    k -= 1;
    memcpy(sb[i].a, str + j, sizeof(char) * (k - j + 1));
    for (j = k + 1; !isalpha(str[j]) && !isdigit(str[j]); j++)
      ;
    for (k = j; str[k] != '\"'; k++)
      ;
    k -= 1;
    memcpy(sb[i].b, str + j, sizeof(char) * (k - j + 1));
  }
  for (int i = 1; i <= n; i++) {
    if (!typ[i]) continue;
    if (typ[i] == 1) s.push(i);
    if (typ[i] == 2) {
      int v = s.top();
      s.pop();
      if (v < st && i > st && strcmp(tga, sb[i].a) == 0) {
        suc(i);
        return 0;
      }
    }
  }
  printf("Unhandled Exception\n");
  return 0;
}
