#include <bits/stdc++.h>
using namespace std;
const int dr[]{-1, -1, 0, 1, 1, 1, 0, -1};
const int dc[]{0, 1, 1, 1, 0, -1, -1, -1};
void run() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
string readLine() {
  string s;
  getline(cin, s);
  string rt;
  bool open = false;
  for (auto &ch : s) {
    if (ch == '"') open = !open;
    if (ch != ' ' || open) rt += ch;
  }
  return rt;
}
string getException(string s) {
  s = s.substr(6);
  s.pop_back();
  return s;
}
vector<string> splitCatch(string s) {
  s = s.substr(6);
  s.pop_back();
  vector<string> rt(2);
  bool idx = 0;
  for (char ch : s) {
    if (ch == '"') continue;
    if (ch == ',')
      idx = 1;
    else
      rt[idx] += ch;
  }
  return rt;
}
vector<string> v, out;
pair<int, set<string>> solve(int idx) {
  set<string> st;
  for (int i = idx + 1; i < (int)(v.size()); i++) {
    if (v[i] == "try") {
      pair<int, set<string>> it = solve(i);
      st.insert(it.second.begin(), it.second.end());
      i = it.first;
      continue;
    }
    string type = v[i].substr(0, 5);
    if (type == "throw") {
      string exp = getException(v[i]);
      st.insert(exp);
    } else if (type == "catch") {
      vector<string> tmp = splitCatch(v[i]);
      if (st.find(tmp[0]) != st.end()) {
        out.push_back(tmp[1]);
        st.erase(tmp[0]);
      }
      return {i, st};
    }
  }
}
int main() {
  run();
  int n;
  cin >> n;
  cin.ignore();
  v = vector<string>(n + 2);
  v[0] = "try";
  v.back() = "catch(,)";
  for (int i = 1; i <= n; i++) v[i] = readLine();
  auto it = solve(0);
  if (it.second.size()) return cout << "Unhandled Exception", 0;
  for (auto &it : out) cout << it << "\n";
}
