#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  cin.ignore();
  int tm = 1;
  int ok = INT_MAX;
  map<string, int> mp, mp2;
  vector<int> S;
  string t, a, key;
  while (n--) {
    string s;
    getline(cin, s);
    if (s.find("catch") != -1) {
      int c = S.back();
      S.pop_back();
      if (c > ok) continue;
      int comma = s.find(",");
      int j = comma - 1;
      while (s[j] != '(') j--;
      j++;
      while (s[j] == ' ') j++;
      comma--;
      while (s[comma] == ' ') comma--;
      comma++;
      string key = s.substr(j, comma - j);
      if (key == t) {
        int p = s.find("\"") + 1;
        int j = p;
        while (s[j] != '\"') j++;
        return cout << s.substr(p, j - p), 0;
      }
    } else if (s.find("throw") != -1) {
      int pos = s.find('(') + 1;
      int j = pos;
      while (s[j] != ')') j++;
      while (s[pos] == ' ') pos++;
      j--;
      while (s[j] == ' ') j--;
      j++;
      t = s.substr(pos, j - pos);
      ok = tm;
    } else if (s.find("try") != -1)
      S.push_back(++tm);
  }
  cout << "Unhandled Exception\n";
}
