#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define mid int m = (l + r) >> 1
const int mod = 201314;
const int M = 2e5 + 10; //建了双向边 *个2
struct node{
int to,next;
}e[M];
int cnt,cnt1,n;
int son[M],siz[M],head[M],fa[M],top[M],dep[M],tid[M],mx[M],rk[M];
int sum[M<<2],lazy[M<<2];
void add(int u,int v){
e[++cnt].to = v;e[cnt].next = head[u];head[u] = cnt;
}
void dfs1(int u,int faz,int deep){
dep[u] = deep;
fa[u] = faz;
siz[u] = 1;
for(int i = head[u];i;i = e[i].next){
int v = e[i].to;
if(v == faz) continue;
dfs1(v,u,deep+1);
siz[u] += siz[v];
if(siz[v] > siz[son[u]]||son[u] == -1)
son[u] = v;
}
}
void dfs2(int u,int t){
top[u] = t;
mx[u] = cnt1;
tid[u] = cnt1;
rk[cnt1] = u;
cnt1++;
if(son[u] == -1) return ;
dfs2(son[u],t),mx[u] = max(mx[u],mx[son[u]]);
for(int i = head[u];i;i=e[i].next){
int v = e[i].to;
if(v != fa[u]&&v != son[u])
dfs2(v,v),mx[u] = max(mx[u],mx[v]);
}
}
void pushup(int rt){
sum[rt] = sum[rt<<1] + sum[rt<<1|1];
}
void pushdown(int l,int r,int rt){
if(lazy[rt]==0){
sum[rt<<1] = sum[rt<<1|1] = 0;
lazy[rt<<1] = lazy[rt<<1|1] = 0;
lazy[rt] = -1;
}
else if(lazy[rt] == 1){
mid;
sum[rt<<1] = m-l+1 ;
sum[rt<<1|1] = r-m;
lazy[rt<<1] = lazy[rt<<1|1] = 1;
lazy[rt] = -1;
}
}
void build(int l,int r,int rt){
lazy[rt] = -1;
if(l == r){
sum[rt] = 0;
lazy[rt] = -1;
return ;
}
mid;
build(lson); build(rson);
}
int update(int L,int R,int c,int l,int r,int rt){
if(L <= l&&R >= r){
if(c==0){
int cnt = sum[rt];
sum[rt] = 0; lazy[rt] = 0;
return cnt;
}
else{
int cnt = r-l+1-sum[rt];
sum[rt] = r-l+1;
lazy[rt] = 1;
return cnt;
}
}
pushdown(l,r,rt);
mid; int ret = 0;
if(L <= m) ret += update(L,R,c,lson);
if(R > m) ret += update(L,R,c,rson);
pushup(rt);
return ret;
}
int solve(int x,int y){
int fx = top[x],fy = top[y];
int ans = 0;
while(fx != fy){
if(dep[fx] < dep[fy]) swap(fx,fy),swap(x,y);
ans += update(tid[fx],tid[x],1,1,n,1);
x = fa[fx]; fx = top[x];
}
if(dep[x] > dep[y]) swap(x,y);
ans += update(tid[x],tid[y],1,1,n,1);
return ans;
}
char s[100];
int main()
{
int x,m;
cnt = 1,cnt1 = 1;
scanf("%d",&n);
memset(son,-1,sizeof(son));
for(int i = 2;i <= n;i ++){
scanf("%d",&x);
add(x+1,i);add(i,x+1);
}
dfs1(1,0,1); dfs2(1,0);
build(1,n,1);
scanf("%d",&m);
for(int i = 1;i <= m;i ++){
scanf("%s",s);
if(s[0] == ‘i‘){
scanf("%d",&x);
x++;
printf("%d\n",solve(x,1));
}
else{
scanf("%d",&x);
x++;
printf("%d\n",update(tid[x],mx[x],0,1,n,1));
}
}
return 0;
}