var
n,q,i,j,num,ans:longint;
f,qq:array[0..100000] of longint;
hj:array[0..5000,-1..5000]of longint;
s:string;
procedure uninstall(num:longint);
var
i:longint;
begin
if f[num]=0 then exit;
inc(ans);
f[num]:=0;
for i:=0 to hj[num,-1]-1 do
uninstall(hj[num,i]);
hj[num,-1]:=0;
end;
begin
assign(input,'manager.in');
reset(input);
assign(output,'manager.out');
rewrite(output);
read(n);
for n:=1 to n-1 do
read(qq[n]);
readln(q);
for q:=1 to q do
begin
readln(s);
num:=0;j:=1;ans:=0;
if s[1]='i' then
begin
for i:=length(s) downto 9 do
begin
num:=num+(ord(s[i])-48)*j;
j:=j*10;
end;
{writeln(num);}
while f[num]=0 do
begin
inc(ans);
f[num]:=1;
inc(hj[qq[num],-1]);
hj[qq[num],hj[qq[num],-1]]:=num;
num:=qq[num];
end;
end;
if s[1]='u' then
begin
for i:=length(s) downto 11 do
begin
num:=num+(ord(s[i])-48)*j;
j:=j*10;
end;
uninstall(num);
end;
writeln(ans);
end;
close(input);
close(output);
end.