program war;
var i,j,k,l,m,n,p,q,r,t,tt,root,d,x:longint;
left,right,father,sontree:array[0..30000] of longint;
hp:array[0..30000] of longint;
heap:array[0..30000] of real;
c:char;
procedure ro(x:longint);
var g,t:longint;
begin
g:=father[x];
sontree[x]:=sontree[g];
sontree[g]:=sontree[right[g]]+sontree[right[x]]+1;
left[g]:=right[x];
father[right[x]]:=g;
if g=root then
begin
root:=x;father[g]:=x;father[x]:=0;right[x]:=g;
end else
begin
if g=left[father[g]] then left[father[g]]:=x else
right[father[g]]:=x;
father[x]:=father[g];
father[g]:=x;right[x]:=g;
end;
end;
procedure lo(x:longint);
var g,t:longint;
begin
g:=father[x];
sontree[x]:=sontree[g];
sontree[g]:=sontree[left[g]]+sontree[left[x]]+1;
right[g]:=left[x];
father[left[x]]:=g;
if g=root then
begin
root:=x;father[g]:=x;father[x]:=0;left[x]:=g;
end else
begin
if g=left[father[g]] then left[father[g]]:=x else
right[father[g]]:=x;
father[x]:=father[g];
father[g]:=x;left[x]:=g;
end;
end;
procedure ins(x:longint);
var g:longint;
begin
g:=root;
sontree[x]:=1;
while true do
begin
inc(sontree[g]);
if hp[x]<hp[g] then
begin
if left[g]=0 then
begin
left[g]:=x;father[x]:=g;break;
end else g:=left[g];
end else
begin
if right[g]=0 then
begin
right[g]:=x;father[x]:=g;break;
end else g:=right[g];
end;
end;
heap[x]:=random;
while (x<>root)and(heap[x]<heap[father[x]]) do
if x=left[father[x]] then ro(x) else lo(x);
end;
procedure del(x:longint);
var g,t:longint;
begin
while true do
begin
if left[x]>0 then ro(left[x]) else
if right[x]>0 then lo(right[x]) else
break;
end;
g:=x;
while g<>root do
begin
g:=father[g];dec(sontree[g]);
end;
if x=left[father[x]] then left[father[x]]:=0 else right[father[x]]:=0;
father[x]:=0;
end;
procedure ask(x:longint);
var g,t:longint;
begin
if sontree[root]<x then
begin
writeln(-1);
exit;
end;
x:=sontree[root]-x+1;
//writeln(x);
g:=root;
while x>0 do
begin
if sontree[left[g]]>=x then g:=left[g] else
if sontree[left[g]]=x-1 then
begin
writeln(hp[g]);
exit;
end else
begin
x:=x-sontree[left[g]]-1;
g:=right[g];
end;
end;
end;
procedure pro_1;
begin
readln(i,d);
dec(hp[i],d);
if sontree[root]>1 then
begin
del(i);
if hp[i]>0 then ins(i);
end;
end;
procedure pro_2;
begin
readln(i,d);
inc(hp[i],d);
if sontree[root]>1 then
begin
del(i);ins(i);
end;
end;
procedure pro_3;
begin
readln(k);
ask(k);
end;
procedure debug(x:longint);
begin
if left[x]>0 then debug(left[x]);
writeln(x,':',hp[x],'---',left[x],' ',right[x],' ',father[x],' ',heap[x]:0:3);
if right[x]>0 then debug(right[x]);
end;
begin
assign(input,'war.in');
reset(input);
assign(output,'war.out');
rewrite(output);
randomize;
readln(n);
for i:=1 to n do read(hp[i]);readln;
root:=1;sontree[1]:=1;heap[1]:=random;
for i:=2 to n do
begin
ins(i);
//debug(root);
//for x:=1 to i do writeln(x,':',hp[x],'---',left[x],' ',right[x],' ',father[x],' ',heap[x]:0:3);
//writeln;
end;
readln(m);
for tt:=1 to m do
begin
read©;
if c='A' then pro_1;
if c='C' then pro_2;
if c='Q' then pro_3;
//debug(root);
end;
if hp[root]>0 then writeln(sontree[root]) else writeln(0);
close(output);
end.
var i,j,k,l,m,n,p,q,r,t,tt,root,d,x:longint;
left,right,father,sontree:array[0..30000] of longint;
hp:array[0..30000] of longint;
heap:array[0..30000] of real;
c:char;
procedure ro(x:longint);
var g,t:longint;
begin
g:=father[x];
sontree[x]:=sontree[g];
sontree[g]:=sontree[right[g]]+sontree[right[x]]+1;
left[g]:=right[x];
father[right[x]]:=g;
if g=root then
begin
root:=x;father[g]:=x;father[x]:=0;right[x]:=g;
end else
begin
if g=left[father[g]] then left[father[g]]:=x else
right[father[g]]:=x;
father[x]:=father[g];
father[g]:=x;right[x]:=g;
end;
end;
procedure lo(x:longint);
var g,t:longint;
begin
g:=father[x];
sontree[x]:=sontree[g];
sontree[g]:=sontree[left[g]]+sontree[left[x]]+1;
right[g]:=left[x];
father[left[x]]:=g;
if g=root then
begin
root:=x;father[g]:=x;father[x]:=0;left[x]:=g;
end else
begin
if g=left[father[g]] then left[father[g]]:=x else
right[father[g]]:=x;
father[x]:=father[g];
father[g]:=x;left[x]:=g;
end;
end;
procedure ins(x:longint);
var g:longint;
begin
g:=root;
sontree[x]:=1;
while true do
begin
inc(sontree[g]);
if hp[x]<hp[g] then
begin
if left[g]=0 then
begin
left[g]:=x;father[x]:=g;break;
end else g:=left[g];
end else
begin
if right[g]=0 then
begin
right[g]:=x;father[x]:=g;break;
end else g:=right[g];
end;
end;
heap[x]:=random;
while (x<>root)and(heap[x]<heap[father[x]]) do
if x=left[father[x]] then ro(x) else lo(x);
end;
procedure del(x:longint);
var g,t:longint;
begin
while true do
begin
if left[x]>0 then ro(left[x]) else
if right[x]>0 then lo(right[x]) else
break;
end;
g:=x;
while g<>root do
begin
g:=father[g];dec(sontree[g]);
end;
if x=left[father[x]] then left[father[x]]:=0 else right[father[x]]:=0;
father[x]:=0;
end;
procedure ask(x:longint);
var g,t:longint;
begin
if sontree[root]<x then
begin
writeln(-1);
exit;
end;
x:=sontree[root]-x+1;
//writeln(x);
g:=root;
while x>0 do
begin
if sontree[left[g]]>=x then g:=left[g] else
if sontree[left[g]]=x-1 then
begin
writeln(hp[g]);
exit;
end else
begin
x:=x-sontree[left[g]]-1;
g:=right[g];
end;
end;
end;
procedure pro_1;
begin
readln(i,d);
dec(hp[i],d);
if sontree[root]>1 then
begin
del(i);
if hp[i]>0 then ins(i);
end;
end;
procedure pro_2;
begin
readln(i,d);
inc(hp[i],d);
if sontree[root]>1 then
begin
del(i);ins(i);
end;
end;
procedure pro_3;
begin
readln(k);
ask(k);
end;
procedure debug(x:longint);
begin
if left[x]>0 then debug(left[x]);
writeln(x,':',hp[x],'---',left[x],' ',right[x],' ',father[x],' ',heap[x]:0:3);
if right[x]>0 then debug(right[x]);
end;
begin
assign(input,'war.in');
reset(input);
assign(output,'war.out');
rewrite(output);
randomize;
readln(n);
for i:=1 to n do read(hp[i]);readln;
root:=1;sontree[1]:=1;heap[1]:=random;
for i:=2 to n do
begin
ins(i);
//debug(root);
//for x:=1 to i do writeln(x,':',hp[x],'---',left[x],' ',right[x],' ',father[x],' ',heap[x]:0:3);
//writeln;
end;
readln(m);
for tt:=1 to m do
begin
read©;
if c='A' then pro_1;
if c='C' then pro_2;
if c='Q' then pro_3;
//debug(root);
end;
if hp[root]>0 then writeln(sontree[root]) else writeln(0);
close(output);
end.