#include <bits/stdc++.h>
using namespace std;
string line;
string ex;
vector<string> program;
vector<int> type;
vector<int> another;
vector<int> depth;
vector<bool> is;
enum { TRY, THROW, CATCH };
int detect(string& s) {
  for (int i = 0; i < s.size(); i++) {
    if (s[i] != ' ') {
      if (s[i + 1] == 'r') return TRY;
      if (s[i + 1] == 'h') return THROW;
      if (s[i + 1] == 'a') return CATCH;
      break;
    }
  }
  return -1;
}
pair<string, string> destruct(string& s) {
  int p = s.find('(') + 1;
  string word, saying;
  int i;
  for (; s[p] == ' '; p++)
    ;
  for (i = p; s[i] != ' ' && s[i] != ','; i++) {
    word += s[i];
  }
  for (; s[i] != '\"'; i++)
    ;
  i++;
  for (; s[i] != '\"'; i++) {
    saying += s[i];
  }
  return make_pair(word, saying);
}
void pre() {
  stack<int> stk;
  stack<int> stk2;
  for (int i = 0; i < program.size(); i++) {
    if (type[i] == TRY) {
      stk.push(i);
    } else if (type[i] == CATCH) {
      another[stk.top()] = i;
      stk.pop();
    } else if (type[i] == THROW) {
      stk2 = stk;
      while (!stk2.empty()) {
        depth[stk2.top()] = stk2.size();
        stk2.pop();
      }
    }
  }
}
int main() {
  int n;
  while (scanf("%d", &n) != EOF) {
    getline(cin, line);
    program.clear();
    type.clear();
    depth.clear();
    another.clear();
    for (int i = 0; i < n; i++) {
      getline(cin, line);
      int s = -1;
      for (int i = 0; i < line.size(); i++) {
        if (line[i] != ' ') {
          s = i;
          break;
        }
      }
      if (s == -1) continue;
      line = line.substr(s);
      program.push_back(line);
      int t = detect(line);
      depth.push_back(0);
      another.push_back(-1);
      type.push_back(t);
      if (t == THROW) {
        ex = "";
        int p = line.find('(') + 1;
        for (; line[p] == ' '; p++)
          ;
        for (; line[p] != ' ' && line[p] != ')'; p++) {
          ex += line[p];
        }
      }
    }
    pre();
    int maxdepth = 0;
    string ans = "Unhandled Exception";
    for (int i = 0; i < program.size(); i++) {
      if (depth[i] > maxdepth) {
        pair<string, string> pss = destruct(program[another[i]]);
        if (pss.first == ex) {
          ans = pss.second;
          maxdepth = depth[i];
        }
      }
    }
    cout << ans << endl;
  }
}
