#include <bits/stdc++.h>
using namespace std;
string f(string s) {
  int i = 0, j = s.size() - 1;
  while (s[i] == ' ') i++;
  while (s[j] == ' ') j--;
  return s.substr(i, j - i + 1);
}
int main() {
  int n;
  scanf("%d\n", &n);
  int b = 0;
  string tp = "";
  for (int i = 0; i < n; i++) {
    string s;
    getline(cin, s);
    if (s == "") continue;
    int a = -1, c;
    bool fl = 0;
    for (int j = s.size() - 1; j >= 0; j--)
      if (s[j] == ')')
        a = j;
      else if (s[j] == '(') {
        for (int z = j - 1; z >= 0; z--)
          if (s[z] == 'w') {
            fl = 1;
            break;
          }
        string g = f(s.substr(j + 1, a - j - 1));
        if (fl) {
          b = 1;
          tp = g;
        } else {
          if (b == 1) {
            int ps = g.find(',');
            if (tp == f(g.substr(0, ps))) {
              g = f(g.substr(ps + 1, s.size() - ps - 1));
              cout << g.substr(1, g.size() - 2) << endl;
              return 0;
            }
          }
        }
        break;
      }
    if (a >= 0) {
      if (b > 1) b--;
    } else if (b)
      b++;
  }
  puts("Unhandled Exception");
}
