#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
template <class T>
T gcd(T x, T y) {
  while (T t = x % y) x = y, y = t;
  return y;
}
const double eps = 1e-9;
const double PI = acos(-1.);
const int INF = 1000000000;
const int MOD = 1000000007;
const double E = 2.7182818284590452353602874713527;
bool isdig(char x) { return x >= '0' && x <= '9'; }
bool isup(char x) { return x >= 'A' && x <= 'Z'; }
bool isdown(char x) { return x >= 'a' && x <= 'z'; }
bool islet(char x) { return isup(x) || isdown(x); }
int N;
void get_data() { scanf("%d", &N); }
string gettar(char s[], int l) {
  string r = "";
  bool f = 0;
  for (int i = 0; i < l; i++) {
    if (s[i] == '(') {
      f = 1;
      continue;
    }
    if (s[i] == ')') return r;
    if (!f) continue;
    if (s[i] == ' ') continue;
    r += s[i];
  }
  return "";
}
void getit(char s[], int l, string &a, string &b) {
  a = b = "";
  int tp = 0;
  for (int i = 0; i < l; i++) {
    if (s[i] == '(')
      tp = 1;
    else if (s[i] == '"')
      tp++;
    else if (s[i] == ')')
      tp = 0;
    else {
      if (tp == 2)
        b += s[i];
      else if (tp == 1 && islet(s[i]))
        a += s[i];
    }
  }
}
void run() {
  getchar();
  char com[1005];
  string a, b;
  string tar;
  bool flag = 0;
  int cnt = 0;
  bool stttp = 0;
  while (N--) {
    gets(com);
    if (stttp) continue;
    int typ = -1, l = strlen(com);
    for (int i = 0; i < l; i++) {
      if (com[i] == ' ') continue;
      if (com[i] == 't' && com[i + 1] == 'h')
        typ = 0;
      else if (com[i] == 't')
        typ = 1;
      else
        typ = 2;
      break;
    }
    if (typ == -1) continue;
    if (typ == 0) {
      tar = gettar(com, l);
      flag = 1;
    } else if (typ == 1) {
      if (flag) cnt++;
    } else {
      if (!flag) continue;
      if (cnt) {
        cnt = max(0, cnt - 1);
        continue;
      }
      getit(com, l, a, b);
      if (a == tar) {
        cout << b << endl;
        stttp = 1;
        continue;
      }
      cnt = max(0, cnt - 1);
    }
  }
  if (!stttp) cout << "Unhandled Exception" << endl;
}
int main() {
  {
    get_data();
    run();
  }
  return 0;
}
