#include <cstdio>
#include <cstring>
inline int readint() {
int n = 0;
char ch = getchar();
while (ch < ‘0‘ || ch > ‘9‘) ch = getchar();
while (ch <= ‘9‘ && ch >= ‘0‘) {
n = (n << 1) + (n << 3) + ch - ‘0‘;
ch = getchar();
}
return n;
}
const int maxn = 100000 + 10;
struct Edge {
int to, next;
Edge() {}
Edge(int _t, int _n) : to(_t), next(_n) {}
}e[maxn];
int fir[maxn] = { 0 }, cnt = 0;
inline void add(int u, int v) {
e[++cnt] = Edge(v, fir[u]); fir[u] = cnt;
}
int fa[maxn], dep[maxn], siz[maxn], son[maxn];
void dfs1(int u) {
siz[u] = 1;
son[u] = 0;
for (int v, i = fir[u]; i; i = e[i].next) {
v = e[i].to;
fa[v] = u;
dep[v] = dep[u] + 1;
dfs1(v);
siz[u] += siz[v];
if (!son[u] || siz[v] > siz[son[u]]) son[u] = v;
}
}
int top[maxn], in[maxn], out[maxn], tcnt = 0;
void dfs2(int u) {
in[u] = ++tcnt;
if (!son[u]) {
out[u] = in[u];
return;
}
top[son[u]] = top[u];
dfs2(son[u]);
for (int v, i = fir[u]; i; i = e[i].next) {
v = e[i].to;
if (v == son[u]) continue;
top[v] = v;
dfs2(v);
}
out[u] = tcnt;
}
#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
int sum[maxn << 2], tag[maxn << 2];
void Build(int l, int r, int rt) {
sum[rt] = 0;
tag[rt] = -1;
if (l == r) return;
else {
int mid = l + r >> 1;
Build(lson);
Build(rson);
}
}
inline void PushUp(int rt) {
sum[rt] = sum[rt << 1] + sum[rt << 1 | 1];
}
inline void PushDown(int rt, int len) {
if (tag[rt] == 0) {
sum[rt << 1] = sum[rt << 1 | 1] = 0;
tag[rt << 1] = tag[rt << 1 | 1] = 0;
tag[rt] = -1;
}
if (tag[rt] == 1) {
sum[rt << 1] = len - (len >> 1);
sum[rt << 1 | 1] = len >> 1;
tag[rt << 1] = tag[rt << 1 | 1] = 1;
tag[rt] = -1;
}
}
int Query(int ql, int qr, int l, int r, int rt) {
if (ql <= l && r <= qr) return sum[rt];
else {
PushDown(rt, r - l + 1);
int mid = l + r >> 1, ret = 0;
if (ql <= mid) ret += Query(ql, qr, lson);
if (qr > mid) ret += Query(ql, qr, rson);
return ret;
}
}
void Update(int ql, int qr, int qv, int l, int r, int rt) {
if (ql <= l && r <= qr) {
tag[rt] = qv;
if (qv == 0) sum[rt] = 0;
else sum[rt] = r - l + 1;
}
else {
PushDown(rt, r - l + 1);
int mid = l + r >> 1;
if (ql <= mid) Update(ql, qr, qv, lson);
if (qr > mid) Update(ql, qr, qv, rson);
PushUp(rt);
}
}
int n;
void work1() {
int x = readint() + 1, ans = 0;
while (top[x] != 1) {
ans += dep[x] - dep[top[x]] + 1 - Query(in[top[x]], in[x], 1, n, 1);
Update(in[top[x]], in[x], 1, 1, n, 1);
x = fa[top[x]];
}
ans += dep[x] - dep[1] + 1 - Query(in[1], in[x], 1, n, 1);
Update(in[1], in[x], 1, 1, n, 1);
printf("%d\n", ans);
}
void work2() {
int x = readint() + 1;
printf("%d\n", Query(in[x], out[x], 1, n, 1));
Update(in[x], out[x], 0, 1, n, 1);
}
int main() {
n = readint();
for (int i = 2; i <= n; i++) add(readint() + 1, i);
fa[1] = dep[1] = 0;
dfs1(1);
top[1] = 1;
dfs2(1);
Build(1, n, 1);
int q = readint();
char opt[10];
for (int i = 1; i <= q; i++) {
scanf("%s", opt);
if (opt[0] == ‘i‘) work1();
else work2();
}
return 0;
}