//Pranet Verma
#include <bits/stdc++.h>
using namespace std;
typedef struct Node* pnode;
struct Node
{
pnode l,r;
int prior,cnt,val,mx;
}tree[100005],*pool=tree,*null=tree;
pnode init(int v)
{
++pool;
pool->prior=rand();
pool->val=v;
pool->l=null;
pool->r=null;
pool->cnt=0;
pool->mx=v;
return pool;
}
void update(pnode u)
{
if(u!=null)
{
u->cnt=1+u->l->cnt+u->r->cnt;
u->mx=max(u->val,max(u->l->mx,u->r->mx));
}
}
void split(pnode u,pnode &l,pnode &r,int key,int add)
{
if(u==null)
l=r=null;
else
{
int rank=add+1+u->l->cnt;
if(rank<=key)
{
split(u->r,u->r,r,key,rank);
l=u;
}
else
{
split(u->l,l,u->l,key,add);
r=u;
}
}
update(u);
}
void merge(pnode &u,pnode l,pnode r)
{
if(l==null)
u=r;
else if(r==null)
u=l;
else
{
if(l->prior > r->prior)
{
merge(l->r,l->r,r);
u=l;
}
else
{
merge(r->l,l,r->l);
u=r;
}
}
update(u);
}
// void display(pnode u,int add=0)
// {
// if(u)
// {
// int rank=add+1+sz(u->l);
// cout<<"At "<<rank<<endl;
// cout<<"Going left"<<endl;
// display(u->l,add);
// cout<<"Back at "<<rank<<endl;
// cout<<"Going right"<<endl;
// display(u->r,rank);
// }
// cout<<"Nothing"<<endl;
// }
int main()
{
null->l=null->r=null;
null->val=null->mx=-2e9;
null->cnt=0;
int m;
scanf("%d\n",&m);
pnode root=null;
while(m--)
{
char ty;
int x,y;
scanf("%c %d %d\n",&ty,&x,&y);
if(ty=='A')
{
pnode l,r;
split(root,l,r,y-1,0);
merge(l,l,init(x));
merge(root,l,r);
}
else if(ty=='Q')
{
pnode A,B,C,temp;
split(root,A,temp,x-1,0);
split(temp,B,C,y,x-1);
printf("%d\n",B->mx);
merge(temp,B,C);
merge(root,A,temp);
}
else
assert(0);
}
}
Ly9QcmFuZXQgVmVybWEKI2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CnR5cGVkZWYgc3RydWN0IE5vZGUqIHBub2RlOwpzdHJ1Y3QgTm9kZQp7CiAgICBwbm9kZSBsLHI7CiAgICBpbnQgcHJpb3IsY250LHZhbCxteDsKfXRyZWVbMTAwMDA1XSwqcG9vbD10cmVlLCpudWxsPXRyZWU7CnBub2RlIGluaXQoaW50IHYpCnsKICAgICsrcG9vbDsKICAgIHBvb2wtPnByaW9yPXJhbmQoKTsKICAgIHBvb2wtPnZhbD12OwogICAgcG9vbC0+bD1udWxsOwogICAgcG9vbC0+cj1udWxsOwogICAgcG9vbC0+Y250PTA7CiAgICBwb29sLT5teD12OwogICAgcmV0dXJuIHBvb2w7Cn0Kdm9pZCB1cGRhdGUocG5vZGUgdSkKewogICAgaWYodSE9bnVsbCkKICAgIHsKICAgICAgICB1LT5jbnQ9MSt1LT5sLT5jbnQrdS0+ci0+Y250OwogICAgICAgIHUtPm14PW1heCh1LT52YWwsbWF4KHUtPmwtPm14LHUtPnItPm14KSk7CiAgICB9Cn0Kdm9pZCBzcGxpdChwbm9kZSB1LHBub2RlICZsLHBub2RlICZyLGludCBrZXksaW50IGFkZCkKewogICAgaWYodT09bnVsbCkKICAgICAgICBsPXI9bnVsbDsKICAgIGVsc2UKICAgIHsKICAgICAgICBpbnQgcmFuaz1hZGQrMSt1LT5sLT5jbnQ7CiAgICAgICAgaWYocmFuazw9a2V5KQogICAgICAgIHsKICAgICAgICAgICAgc3BsaXQodS0+cix1LT5yLHIsa2V5LHJhbmspOwogICAgICAgICAgICBsPXU7CiAgICAgICAgfQogICAgICAgIGVsc2UKICAgICAgICB7CiAgICAgICAgICAgIHNwbGl0KHUtPmwsbCx1LT5sLGtleSxhZGQpOwogICAgICAgICAgICByPXU7CiAgICAgICAgfQogICAgfQogICAgdXBkYXRlKHUpOwp9CnZvaWQgbWVyZ2UocG5vZGUgJnUscG5vZGUgbCxwbm9kZSByKQp7CiAgICBpZihsPT1udWxsKQogICAgICAgIHU9cjsKICAgIGVsc2UgaWYocj09bnVsbCkKICAgICAgICB1PWw7CiAgICBlbHNlCiAgICB7CiAgICAgICAgaWYobC0+cHJpb3IgPiByLT5wcmlvcikKICAgICAgICB7CiAgICAgICAgICAgIG1lcmdlKGwtPnIsbC0+cixyKTsKICAgICAgICAgICAgdT1sOwogICAgICAgIH0KICAgICAgICBlbHNlCiAgICAgICAgewogICAgICAgICAgICBtZXJnZShyLT5sLGwsci0+bCk7CiAgICAgICAgICAgIHU9cjsKICAgICAgICB9CiAgICB9CiAgICB1cGRhdGUodSk7Cn0KLy8gdm9pZCBkaXNwbGF5KHBub2RlIHUsaW50IGFkZD0wKQovLyB7Ci8vICAgICBpZih1KQovLyAgICAgewovLyAgICAgICAgIGludCByYW5rPWFkZCsxK3N6KHUtPmwpOwovLyAgICAgICAgIGNvdXQ8PCJBdCAiPDxyYW5rPDxlbmRsOwovLyAgICAgICAgIGNvdXQ8PCJHb2luZyBsZWZ0Ijw8ZW5kbDsKLy8gICAgICAgICBkaXNwbGF5KHUtPmwsYWRkKTsKLy8gICAgICAgICBjb3V0PDwiQmFjayBhdCAiPDxyYW5rPDxlbmRsOwovLyAgICAgICAgIGNvdXQ8PCJHb2luZyByaWdodCI8PGVuZGw7Ci8vICAgICAgICAgZGlzcGxheSh1LT5yLHJhbmspOwovLyAgICAgfQovLyAgICAgY291dDw8Ik5vdGhpbmciPDxlbmRsOwovLyB9CmludCBtYWluKCkKewogICAgbnVsbC0+bD1udWxsLT5yPW51bGw7CiAgICBudWxsLT52YWw9bnVsbC0+bXg9LTJlOTsKICAgIG51bGwtPmNudD0wOwogICAgaW50IG07CiAgICBzY2FuZigiJWRcbiIsJm0pOwogICAgcG5vZGUgcm9vdD1udWxsOwogICAgd2hpbGUobS0tKQogICAgewogICAgICAgIGNoYXIgdHk7CiAgICAgICAgaW50IHgseTsKICAgICAgICBzY2FuZigiJWMgJWQgJWRcbiIsJnR5LCZ4LCZ5KTsKICAgICAgICBpZih0eT09J0EnKQogICAgICAgIHsKICAgICAgICAgICAgcG5vZGUgbCxyOwogICAgICAgICAgICBzcGxpdChyb290LGwscix5LTEsMCk7CiAgICAgICAgICAgIG1lcmdlKGwsbCxpbml0KHgpKTsKICAgICAgICAgICAgbWVyZ2Uocm9vdCxsLHIpOwogICAgICAgIH0KICAgICAgICBlbHNlIGlmKHR5PT0nUScpCiAgICAgICAgewogICAgICAgICAgICBwbm9kZSBBLEIsQyx0ZW1wOwogICAgICAgICAgICBzcGxpdChyb290LEEsdGVtcCx4LTEsMCk7CiAgICAgICAgICAgIHNwbGl0KHRlbXAsQixDLHkseC0xKTsKICAgICAgICAgICAgcHJpbnRmKCIlZFxuIixCLT5teCk7CiAgICAgICAgICAgIG1lcmdlKHRlbXAsQixDKTsKICAgICAgICAgICAgbWVyZ2Uocm9vdCxBLHRlbXApOwogICAgICAgIH0gICAKICAgICAgICBlbHNlCiAgICAgICAgICAgIGFzc2VydCgwKTsKICAgIH0KfQ==