#include<cstdio>
#define N 100005
inline int read(){
int x=0,c=getchar();
while(c>'9'||c<'0')c=getchar();
while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();
return x;
}
int sz[N],pa[N],top[N],son[N],id[N],im[N],idp=1;
int n,m,a;
char s[16];
int ss[N*2],nx[N*2],sp=N;
void f1(int w){
sz[w]=1;
for(int i=nx[w];i;i=nx[i]){
int u=ss[i];
f1(u);
sz[w]+=sz[u];
if(!son[w]||sz[son[w]]<sz[u])son[w]=u;
}
}
void f2(int w,int tp){
id[w]=idp++;
top[w]=tp;
if(son[w])f2(son[w],tp);
for(int i=nx[w];i;i=nx[i]){
int u=ss[i];
if(u==son[w])continue;
f2(u,u);
}
im[w]=idp-1;
}
int c1[262144];
bool t0[262144];
bool t1[262144];
void down(int w,int L,int R){
if(t0[w]){
t0[w]=0;
if(L<R){
t0[w+w]=t0[w+w+1]=1;
t1[w+w]=t1[w+w+1]=0;
c1[w+w]=c1[w+w+1]=0;
}
}
if(t1[w]){
t1[w]=0;
if(L<R){
t1[w+w]=t1[w+w+1]=1;
t0[w+w]=t0[w+w+1]=0;
c1[w+w]=c1[w+w+1]=(R+1-L)>>1;
}
}
}
int set0(int l,int r,int w=1,int L=1,int R=131072){
int M=L+R>>1,ans=0;
down(w,L,R);
if(L==l&&R==r){
ans=c1[w];
c1[w]=0;
t0[w]=1;
t1[w]=0;
return ans;
}
if(r<=M)ans+=set0(l,r,w+w,L,M);
else if(l>M)ans+=set0(l,r,w+w+1,M+1,R);
else ans+=set0(l,M,w+w,L,M)+set0(M+1,r,w+w+1,M+1,R);
c1[w]=c1[w+w]+c1[w+w+1];
return ans;
}
int set1(int l,int r,int w=1,int L=1,int R=131072){
int M=L+R>>1,ans=0;
down(w,L,R);
if(L==l&&R==r){
ans=R+1-L-c1[w];
c1[w]=R+1-L;
t0[w]=0;
t1[w]=1;
return ans;
}
if(r<=M)ans+=set1(l,r,w+w,L,M);
else if(l>M)ans+=set1(l,r,w+w+1,M+1,R);
else ans+=set1(l,M,w+w,L,M)+set1(M+1,r,w+w+1,M+1,R);
c1[w]=c1[w+w]+c1[w+w+1];
return ans;
}
int main(){
n=read();
for(int i=2;i<=n;i++){
a=pa[i]=read()+1;
ss[sp]=i;
nx[sp]=nx[a];
nx[a]=sp++;
}
f1(1);
f2(1,1);
m=read();
while(m--){
scanf("%s",s);
a=read()+1;
if(s[0]=='i'){
int ans=0;
int t=top[a];
while(a){
ans+=set1(id[t],id[a]);
a=pa[t];t=top[a];
}
printf("%d\n",ans);
}else{
printf("%d\n",set0(id[a],im[a]));
}
}
return 0;
}