1 #include<cstdio>
2 #include<iostream>
3 #define mid (L+R)/2
4 #define lc (rt<<1)
5 #define rc (rt<<1|1)
6 #define maxn 1000000
7 using namespace std;
8
9 int dfn[maxn],TIM = 1,dfn_t[maxn],n,a,b,c,m,pos,tl[maxn];
10 char ctr;
11
12 struct edge{
13 int from,v;
14 }e[maxn];
15
16 struct node{
17 int sum;
18 }Tree[maxn];
19
20 void maintain(int rt){
21 Tree[rt].sum = Tree[lc].sum+Tree[rc].sum;
22 }
23
24 void build(int rt,int L,int R){
25 if(L == R) Tree[rt].sum = 1;
26 else{
27 build(lc,L,mid);
28 build(rc,mid+1,R);
29
30 maintain(rt);
31 }
32 }
33
34 void add(int rt,int L,int R,int pos){
35 if(L == R) Tree[rt].sum ^= 1;
36 else{
37 if(pos <= mid) add(lc,L,mid,pos);
38 else add(rc,mid+1,R,pos);
39
40 maintain(rt);
41 }
42 }
43
44 int query(int rt,int L,int R,int qL,int qR){
45 if(qL <= L && R <= qR) return Tree[rt].sum;
46 else{
47 int ans = 0;
48 if(qL <= mid) ans += query(lc,L,mid,qL,qR);
49 if(qR > mid) ans += query(rc,mid+1,R,qL,qR);
50 return ans;
51 }
52 }
53
54 void PRINT(int rt,int L,int R){
55 if(L == R) printf("%d ",Tree[rt].sum);
56 else{
57 PRINT(lc,L,mid);
58 PRINT(rc,mid+1,R);
59 }
60 }
61
62 int tot,first[maxn];
63 void insert(int u,int v){
64 tot++;
65 e[tot].from = first[u];
66 e[tot].v = v;
67 first[u] = tot;
68 }
69
70 void dfs(int now,int pre){
71 dfn[now] = TIM++;
72 tl[dfn[now]] = now;
73 // Tree[dfn[now]].sum = 1;
74 for(int i = first[now];i;i = e[i].from){
75 int v = e[i].v;
76 if(v != pre){
77 dfs(v,now);
78 }
79 }dfn_t[now] = TIM++;
80 tl[dfn_t[now]] = now;
81 }
82
83 int main(){
84 scanf("%d",&n);
85 for(int i = 1;i < n;i++){
86 scanf("%d%d",&a,&b);
87 insert(a,b);
88 insert(b,a);
89 }
90
91
92 dfs(1,-1);
93 TIM--;
94 // build(1,1,TIM-1);
95 for(int i = 1;i <= n;i++){
96 add(1,1,TIM,dfn[i]);
97 }
98
99 scanf("%d",&m);
100 for(int i = 1;i <= m;i++){
101 cin >> ctr >> pos;
102 if(ctr == ‘C‘) add(1,1,TIM,dfn[pos]);
103 else printf("%d\n",query(1,1,TIM,dfn[pos],dfn_t[pos]));
104 // PRINT(1,1,TIM-1);cout << endl;
105 }
106
107 // for(int i = 1;i <= n;i++){
108 // printf("%d ",dfn[i]);
109 // }cout << "##";
110
111 // for(int i = 1;i <= TIM;i++) printf("%d ",tl[i]);
112
113 return 0;
114 }