#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using LD = long double;
using pii = pair<int, int>;
using pll = pair<LL, LL>;
using pld = pair<LD, LD>;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  cin.ignore();
  stack<int> tries;
  pair<int, string> throw_line = {1e5, ""};
  bool found_sol = false;
  for (int i = 0; i < n; ++i) {
    static string line;
    getline(cin, line);
    if (found_sol) {
      continue;
    }
    int try_pos = line.find("try"), throw_pos = line.find("throw"),
        catch_pos = line.find("catch");
    if (try_pos != line.npos && throw_pos == line.npos &&
        catch_pos == line.npos) {
      tries.emplace(i);
    } else if (throw_pos != line.npos && throw_pos < line.find("(")) {
      throw_line.first = i;
      int j;
      for (j = line.find("("); !isalpha(line[j]); ++j)
        ;
      for (; isalpha(line[j]); throw_line.second += line[j++])
        ;
    } else if (catch_pos != line.npos && catch_pos < line.find("(")) {
      if (tries.top() > throw_line.first) {
        tries.pop();
        continue;
      }
      tries.pop();
      int j;
      for (j = line.find("("); !isalpha(line[j]); ++j)
        ;
      string exc_type;
      for (; isalpha(line[j]); exc_type += line[j++])
        ;
      if (exc_type != throw_line.second) {
        continue;
      }
      found_sol = true;
      for (; line[j] != '"'; ++j)
        ;
      for (++j; line[j] != '"'; cout << line[j++])
        ;
    }
  }
  if (!found_sol) {
    cout << "Unhandled Exception";
  }
}
