//其实这个题的树状数组不是难点,映射是难点
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <fstream>
#define N 100004
using namespace std;
struct edge
{
int v,next;
};
edge all[N];
int n,vis[N],edgehead[N],low[N],pick[N],high[N],tree[N],dep;
int lowbit(int k)
{
return k&(-k);
}
void Modify(int num,int v)
{
while(num <= n)
{
tree[num] += v;
num += lowbit(num);
}
}
int sum(int num)
{
int ans = 0;
while (num > 0)
{
ans += tree[num];
num -= lowbit(num);
}
return ans;
}
void DFS(int u)//先序遍历树
{
low[u] = ++dep;//记录被访问的点是第几次遍历到的,建立起始映射
//printf("low[%d] = %d\n",u,dep);
vis[u] = 1;
for(int i = edgehead[u];i;i=all[i].next)
if(!vis[all[i].v])
DFS(all[i].v);
high[u] = dep;//建立终末映射
//printf("high[%d] = %d\n",u,dep);
}
int main()
{
int i,k,j,anss,m,u,v;
while (scanf("%d",&n)!=EOF)
{
k = 1;
memset(edgehead,0,sizeof(edgehead));
memset(pick,0,sizeof(pick));
memset(vis,0,sizeof(vis));
for(i = 1;i < n;i++)//这个for很神奇,好好体会
{
scanf("%d%d",&u,&v);
all[k].v = v;
all[k].next = edgehead[u];
edgehead[u] = k++;
}
for(i = 1;i <= n;i++)
Modify(i,1);
dep = 0;
DFS(1);//一次深搜,建立映射。
scanf("%d",&m);
getchar();
while (m--)
{
char ch;
scanf("%c %d",&ch,&u);
getchar();
if(ch == 'C')
{
if(pick[u])
{
Modify(low[u],1);
pick[u] = 0;
}
else
{
Modify(low[u],-1);
pick[u] = 1;
}
}
else
{
anss = sum(high[u])-sum(low[u]-1);
printf("%d\n",anss);
}
}
}
return 0;
}