#include <bits/stdc++.h>
using namespace std;
class blocks {
 public:
  int blno, elno;
  string type, msg;
  blocks() {}
  blocks(int b, int e, string t, string m) {
    blno = b;
    elno = e;
    type = t;
    msg = m;
  }
};
int main() {
  int n, tn;
  string tty;
  cin >> n;
  stack<int> stk;
  vector<blocks> v;
  char d[50];
  cin.getline(d, 50);
  for (int i = 0; i < n; i++) {
    char c[1000];
    cin.getline(c, 1000);
    string s(c);
    string news = s;
    s.erase(remove(s.begin(), s.end(), ' '), s.end());
    string com = s.substr(0, s.find("("));
    if (com.compare("try") == 0) {
      stk.push(i);
    } else if (com.compare("catch") == 0) {
      string m =
          news.substr(news.find('"') + 1, news.rfind('"') - 1 - news.find('"'));
      s.replace(0, 6, "");
      string ty = s.substr(0, s.find(','));
      s.replace(0, ty.length() + 2, "");
      s.replace(s.length() - 2, 2, "");
      v.push_back(blocks(stk.top(), i, ty, m));
      stk.pop();
    } else if (com.compare("throw") == 0) {
      s.replace(0, 6, "");
      s.replace(s.length() - 1, 1, "");
      tn = i;
      tty = s;
    }
  }
  for (vector<blocks>::iterator it = v.begin(); it != v.end(); it++) {
    if ((it->blno < tn) && (it->elno > tn) && (it->type.compare(tty) == 0)) {
      cout << it->msg;
      return 0;
    }
  }
  cout << "Unhandled Exception";
  return 0;
}
