#include <iostream>
#include <stdio.h>
#include <utility>
#include <vector>
#include <algorithm>
using namespace std;
#define int long long
const int MAX_N = 1e5 + 5;
const int INF = 1e11;
pair<string, int> input[MAX_N];
vector<int> tmp;
int num[MAX_N];
struct Node {
Node* lc;
Node* rc;
int val;
int Max;
int Min;
Node() {
lc=rc=NULL;
val = INF;
Min = INF;
Max = -INF;
}
void pull() {
Min = min(lc->Min,rc->Min);
Max = max(lc->Max,rc->Max);
}
};
Node* Build(int L,int R) {
Node* node = new Node();
if (L==R) {
return node;
}
int mid=(L+R)>>1;
node->lc=Build(L,mid);
node->rc=Build(mid+1,R);
node->pull();
return node;
}
void modify(Node* node,int L,int R,int pos,int val) {
if (L==R) {
if (val==INF) {
node->Max = -INF;
node->Min = INF;
node->val = INF;
return;
}
node->val = val;
node->Max = node->Min = val;
return;
}
int mid = (L+R)>>1;
if (pos<=mid) modify(node->lc,L,mid,pos,val);
else modify(node->rc,mid+1,R,pos,val);
node->pull();
return;
}
int Lans, Rans;
void query(Node* node,int L,int R,int pos) {
// cout<<L<<"~"<<R<<" : ";
// cout<<Lans<<" "<<Rans<<endl;
if (L==R) {
if (node->val != INF) {
Lans=Rans=node->val;
return;
}
return;
}
int mid=(L+R)>>1;
if (pos<=mid) {
Rans = min(node->rc->Min,Rans);
query(node->lc,L,mid,pos);
}
else {
Lans = max(node->lc->Max,Lans);
query(node->rc,mid+1,R,pos);
}
}
main () {
//ios::sync_with_stdio(0);
//cin.tie(0);
int n;
while (cin >> n) {
for (int x=0;n>x;x++) {
string i;
int j;
cin >> i >> j;
input[x]=make_pair(i,j);
num[x]=j;
tmp.push_back(j);
}
sort(tmp.begin(),tmp.end());
tmp.resize(unique(tmp.begin(),tmp.end()) - tmp.begin());
for (int x=0;n>x;x++) num[x] = lower_bound(tmp.begin(),tmp.end(),num[x]) - tmp.begin();
Node* root=Build(0,n);
for (int x=0;n>x;x++) {
if (input[x].first == "insert") {
modify(root,0,n,num[x],input[x].second);
}
else if (input[x].first=="delete") {
modify(root,0,n,num[x],INF);
}
else {
Lans=-INF;
Rans=INF;
query(root,0,n,num[x]);
// cout<<Lans << ' '<<Rans<<endl;
if (Lans==Rans) {
cout<<Lans<<endl;
}
else if (Lans==-INF) {
cout<<Rans<<endl;
}
else if (Rans==INF) {
cout<<Lans<<endl;
}
else if (input[x].second - Lans < Rans - input[x].second) {
cout<<Lans<<endl;
}
else if (input[x].second - Lans > Rans - input[x].second) {
cout<<Rans<<endl;
}
else {
cout<<Lans<<' '<<Rans<<endl;
}
}
}
}
}