# [树状数组套权值线段树] BZOJ 1901 Zju2112 Dynamic Rankings

#include<cstdio>
#include<cstdlib>
#include<algorithm>
#define V G[p].v
using namespace std;
typedef long long ll;

inline char nc()
{
static char buf[100000],*p1=buf,*p2=buf;
if (p1==p2) { p2=(p1=buf)+fread(buf,1,100000,stdin); if (p1==p2) return EOF; }
return *p1++;
}

{
char c=nc(),b=1;
for (;!(c>='0' && c<='9');c=nc()) if (c=='-') b=-1;
for (x=0;c>='0' && c<='9';x=x*10+c-'0',c=nc()); x*=b;
}

for (x=nc();x!='Q' && x!='C';x=nc());
}

const int N=10005;
const int M=5000005;

int sx[2*N],icnt;
inline int Bin(int x){
return lower_bound(sx+1,sx+icnt+1,x)-sx;
}

int Stk[M],pnt;
inline void Init(){ for (int i=M-1;i;i--) Stk[++pnt]=i; }
inline int New(){ return Stk[pnt--]; }
inline void Del(int x){ Stk[++pnt]=x; }

int c[N],ls[M],rs[M],sum[M];

inline void Modify(int &x,int f,int t,int l,int r){
int mid=(l+r)>>1;
if (!x) x=New();
if (l==r)
sum[x]+=f;
else if (t<=mid)
Modify(ls[x],f,t,l,mid),sum[x]=sum[ls[x]]+sum[rs[x]];
else
Modify(rs[x],f,t,mid+1,r),sum[x]=sum[ls[x]]+sum[rs[x]];
if (!sum[x]) Del(x),x=0;
}

int L[1005],R[1005],ltot,rtot;

inline int Query(int l,int r,int K){
if (l==r) return sx[l];
int tmp=0,mid=(l+r)>>1;
for (int i=1;i<=rtot;i++) tmp+=sum[ls[R[i]]];
for (int i=1;i<=ltot;i++) tmp-=sum[ls[L[i]]];
if (K<=tmp)
{
for (int i=1;i<=rtot;i++) R[i]=ls[R[i]];
for (int i=1;i<=ltot;i++) L[i]=ls[L[i]];
return Query(l,mid,K);
}
else
{
for (int i=1;i<=rtot;i++) R[i]=rs[R[i]];
for (int i=1;i<=ltot;i++) L[i]=rs[L[i]];
return Query(mid+1,r,K-tmp);
}
}

int n,a[N];

#define lowbit(x) ((x)&-(x))
inline void add(int x,int f,int r){
for (int i=x;i<=n;i+=lowbit(i))
Modify(c[i],f,r,1,icnt);
}

inline int query(int s,int t,int K){
ltot=rtot=0;
for (int i=s-1;i;i-=lowbit(i)) L[++ltot]=c[i];
for (int i=t;i;i-=lowbit(i)) R[++rtot]=c[i];
return Query(1,icnt,K);
}

struct abcd{
char f;
int a,b,c;
}eve[N];
int Q;

int main()
{
freopen("t.in","r",stdin);
freopen("t.out","w",stdout);
Init();
for (int i=1;i<=Q;i++)
{
if (eve[i].f=='C') sx[++icnt]=eve[i].b;
}
sort(sx+1,sx+icnt+1);
icnt=unique(sx+1,sx+icnt+1)-sx-1;
for (int i=1;i<=n;i++)
for (int i=1;i<=Q;i++)
if (eve[i].f=='Q')
printf("%d\n",query(eve[i].a,eve[i].b,eve[i].c));
else
}