#include <bits/stdc++.h>
using namespace std;
template <class T>
ostream& operator<<(ostream& os, vector<T> v) {
  for (T x : v) os << x << " ";
  return os;
}
template <class T>
istream& operator>>(istream& is, vector<T> v) {
  for (T& x : v) is >> x;
  return is;
}
const long long INF = 1LL << 60;
bool startsWith(string s, string t) {
  return s.size() >= t.size() && s.substr(0, t.size()) == t;
}
string chomp(string s) {
  if (s.empty()) return "";
  long long start = -1, end = -1;
  for (long long i = 0; i < (long long)(s.size()); i++) {
    if (s[i] == ' ') continue;
    start = i;
    break;
  }
  for (long long i = s.size() - 1; i >= 0; i--) {
    if (s[i] == ' ') continue;
    end = i;
    break;
  }
  string ans = "";
  for (long long i = start; i <= end; i++) ans.push_back(s[i]);
  return ans;
}
string parseThrow(string s) {
  long long a, b;
  for (long long i = 0; i < (long long)(s.size()); i++) {
    char c = s[i];
    if (c == '(')
      a = i;
    else if (c == ')')
      b = i;
  }
  return chomp(s.substr(a + 1, b - a - 1));
}
pair<string, string> parseCatch(string s) {
  string a, b;
  long long x, y = -1, z, w;
  for (long long i = 0; i < (long long)(s.size()); i++) {
    char c = s[i];
    if (c == '(') {
      x = i;
    } else if (c == '"') {
      if (y == -1)
        y = i;
      else
        z = i;
    } else if (c == ',')
      w = i;
  }
  a = chomp(s.substr(x + 1, w - x - 1));
  b = chomp(s.substr(y + 1, z - y - 1));
  return make_pair(a, b);
}
void run() {
  long long n;
  cin >> n;
  cin.ignore();
  vector<string> v;
  string buf;
  for (long long i = 0; i < (long long)(n); i++) {
    getline(cin, buf);
    v.push_back(chomp(buf));
  }
  string exn;
  bool flg = false;
  long long depth = 0;
  for (long long i = 0; i < (long long)(n); i++) {
    string s = v[i];
    if (s.empty()) continue;
    if (startsWith(s, "throw")) {
      flg = true;
      exn = parseThrow(s);
    }
    if (!flg) continue;
    if (startsWith(s, "try")) {
      depth++;
    } else if (startsWith(s, "catch")) {
      if (depth > 0) {
        depth--;
        continue;
      } else {
        pair<string, string> e = parseCatch(s);
        if (e.first == exn) {
          cout << e.second << endl;
          return;
        }
      }
    }
  }
  cout << "Unhandled Exception" << endl;
}
int main() {
  run();
  return 0;
}
