program zht;
var
t,ans,n,i,j,q,c:longint;
z:string;
l,zt:array[0..200000] of longint;
procedure az;
begin
t:=c;
ans:=ans+1;
zt[t]:=1;
while t<>0 do
if zt[l[t]]=0 then begin ans:=ans+1;zt[l[t]]:=1;t:=l[t];end
else t:=0;
writeln(ans);
end;
procedure sc(m:longint);
var
p:longint;
begin
for p:=1 to n do
if l[p]=m then if zt[p]=1 then begin zt[p]:=0;ans:=ans+1;sc(p);end;
end;
begin
assign(input,'manager.in');
assign(output,'manager.out');
reset(input);
rewrite(output);
readln(n);
for i:=1 to n-1 do
read(l[i]);
readln(q);
for i:=1 to q do
begin
readln(z);
ans:=0;
c:=0;
for j:=1 to length(z) do
if (z[j]>='0') and (z[j]<='9') then c:=c*10+ord(z[j])-48;
if z[1]='i' then if zt[c]=1 then begin writeln('0');continue;end;
if z[1]='u' then if zt[c]=0 then begin writeln('0');continue;end;
if z[1]='i' then az;
if z[1]='u' then begin zt[c]:=0;sc(c);ans:=ans+1;writeln(ans);end;
end;
close(input);
close(output);
end.