#include<iostream>
#include<set>
#include<string>
#include<utility>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
int main(){
set<pair<int, string>> people;
int n;
cin >> n;
while(n--){
int age;
string name, buf;
cin >> buf;
if(buf == "born"){
cin >> name >> age;
people.insert(make_pair(age, name));
}
else if(buf == "find"){
cin >> name >> age;
if(people.find(make_pair(age, name)) != people.end()) cout << "YES" << endl;
else cout << "NO" << endl;
}
else if(buf == "kill"){
cin >> name >> age;
people.erase(make_pair(age, name));
}
else {
if(!people.empty()){
cout << (people.begin())->second << ' ' << (people.begin())->first << endl;
}
}
}
return 0;
}