#include <bits/stdc++.h>
using namespace std;
const int mod = (int)1e9 + 7;
const int inf = (int)(1e9);
const int N = 100005;
int n;
string s;
int ind1, ind2;
string thro;
string dop;
int j;
int main() {
  int i = 0;
  scanf("%d\n", &n);
  for (; i < n; ++i) {
    getline(cin, s);
    j = 0;
    while (s[j] == ' ' && j < (int)s.size()) j++;
    if (j == (int)s.size()) continue;
    if (s[j] == 't' && s[j + 1] == 'h') {
      j += 4;
      while (s[j] != '(') ++j;
      ++j;
      while (s[j] == ' ') ++j;
      ind1 = j;
      while (s[j] != ' ' && s[j] != ')') ++j;
      ind2 = j - 1;
      thro = s.substr(ind1, ind2 - ind1 + 1);
      break;
    }
  }
  int flag = 0;
  int dif = 0;
  for (; i < n; ++i) {
    getline(cin, s);
    j = 0;
    while (s[j] == ' ' && j < (int)s.size()) j++;
    if (j == (int)s.size()) continue;
    if (s[j] == 't' && s[j + 1] == 'r') {
      dif++;
      continue;
    }
    if (s[j] == 'c' && s[j + 1] == 'a' && dif > 0) {
      dif--;
      continue;
    }
    j += 5;
    while (s[j] != '(') ++j;
    ++j;
    while (s[j] == ' ') ++j;
    ind1 = j;
    while (s[j] != ' ' && s[j] != ',') ++j;
    ind2 = j - 1;
    dop = s.substr(ind1, ind2 - ind1 + 1);
    if (dop != thro) continue;
    while (s[j] != '"') ++j;
    ++j;
    ind1 = j;
    while (s[j] != '"') ++j;
    ind2 = j - 1;
    cout << s.substr(ind1, ind2 - ind1 + 1);
    return 0;
  }
  cout << "Unhandled Exception" << endl;
  return 0;
}
