#include<bits/stdc++.h>
#define N 1000005
#define int long long
using namespace std;
struct Chtholly{
int l,r;
mutable int v;
Chtholly(int l,int r=-1,int v=-1):l(l),r(r),v(v){}
bool operator<(const Chtholly& a)const{
return l<a.l;
}
};
struct star{
int next,to;
}e[N];
set<Chtholly>s;
int last,n,m,cnt,tot,head[N],tp[N],dot[N],fa[N],siz[N],son[N],dep[N];
void add(int u,int v){
e[++cnt].next=head[u];
head[u]=cnt;
e[cnt].to=v;
}
set<Chtholly>::iterator split(int p){
auto it=s.lower_bound(Chtholly(p));
if(it!=s.end()&&it->l==p) return it;
it--;
if(it->r<p) return s.end();
int l=it->l,r=it->r,v=it->v;
s.erase(it);
s.insert(Chtholly(l,p-1,v));
return s.insert(Chtholly(p,r,v)).first;
}
void assign(int l,int r,int v){
auto itr=split(r+1),itl=split(l);
s.erase(itl,itr);
s.insert(Chtholly(l,r,v));
}
void dfs1(int x,int f){
fa[x]=f,siz[x]=1,dep[x]=dep[f]+1,son[x]=n+1;
for(int i=head[x];i;i=e[i].next){
int y=e[i].to;
if(y==f) continue;
dfs1(y,x);
siz[x]+=siz[y];
if(siz[y]>siz[son[x]]) son[x]=y;
}
}
void dfs2(int x,int f){
dot[x]=++tot,tp[x]=f;
if(son[x]==n+1) return;
dfs2(son[x],f);
for(int i=head[x];i;i=e[i].next){
int y=e[i].to;
if(y==fa[x]||y==son[x]) continue;
dfs2(y,y);
}
}
void solve1(int x,int y){
while(tp[x]!=tp[y]){
if(dep[tp[x]]<dep[tp[y]]) swap(x,y);
assign(dot[tp[x]],dot[x],1);
x=fa[tp[x]];
}
if(dot[x]>dot[y]) swap(x,y);
assign(dot[x],dot[y],1);
int res=0;
for(auto it=s.begin();it!=s.end();it++){
if(it->v) res+=it->r-it->l+1;
}
cout<<abs(res-last)<<endl,last=res;
}
void solve2(int x){
assign(dot[x],dot[x]+siz[x]-1,0);
int res=0;
for(auto it=s.begin();it!=s.end();it++){
if(it->v) res+=it->r-it->l+1;
}
cout<<abs(res-last)<<endl,last=res;
}
signed main(){
ios::sync_with_stdio(false);
cin>>n;
s.insert(Chtholly(1,n+1,0));
for(int i=1,u;i<n;i++) cin>>u,add(u,i);
dfs1(0,n+1);
dfs2(0,0);
cin>>m;
string s;int x;
while(m--){
cin>>s>>x;
if(s=="install") solve1(x,0);
else solve2(x);
}
return 0;
}