#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
const long long LLINF = 9223372036854775807LL;
const int ST = 100010;
const int ST1 = 1000010;
const long long MOD = 1000000007;
long long ABS(long long a) {
  if (a < 0)
    return a * (-1);
  else
    return a;
}
char a[60];
vector<int> p;
int main() {
  int n;
  cin >> n;
  string m;
  m = "Unhandled Exception";
  string ex = "";
  gets(a);
  for (int i = 0; i < n; i++) {
    gets(a);
    int l = strlen(a);
    for (int i = 0; i < l; i++) {
      if (a[i] == 't' && a[i + 1] == 'r') {
        p.push_back(1);
        break;
      } else if (a[i] == 't' && a[i + 1] == 'h') {
        for (int j = i + 5; j < l; j++) {
          if ((a[j] >= 'a' && a[j] <= 'z') || (a[j] >= 'A' && a[j] <= 'Z')) {
            while ((a[j] >= 'a' && a[j] <= 'z') ||
                   (a[j] >= 'A' && a[j] <= 'Z')) {
              ex += a[j];
              j++;
            }
            break;
          }
        }
        if (!p.empty()) p[(int)((p).size()) - 1] = 2;
        break;
      } else if (a[i] == 'c') {
        string e = "", r = "";
        int j;
        for (j = i + 5; j < l; j++) {
          if ((a[j] >= 'a' && a[j] <= 'z') || (a[j] >= 'A' && a[j] <= 'Z')) {
            while ((a[j] >= 'a' && a[j] <= 'z') ||
                   (a[j] >= 'A' && a[j] <= 'Z')) {
              e += a[j];
              j++;
            }
            break;
          }
        }
        for (j = j + 1; j < l; j++) {
          if (a[j] == '\"') {
            j++;
            while (a[j] != '\"') {
              r += a[j];
              j++;
            }
          }
        }
        if (p[(int)((p).size()) - 1] == 2) {
          if (ex == e) {
            m = r;
            p[(int)((p).size()) - 1] = 1;
          }
        }
        int q = p[(int)((p).size()) - 1];
        p.pop_back();
        if (!p.empty() && q == 2) p[(int)((p).size()) - 1] = 2;
        break;
      }
    }
  }
  cout << m;
}
