1 {$inline on}
2 {$M 10000000,0,maxlongint}
3 const maxn=300000+100;
4 type node=record
5 go,next:longint;
6 end;
7
8 var e:array[0..2*maxn] of node;
9 head,dep,l,r:array[0..maxn] of longint;
10 s:array[0..2*maxn] of longint;
11 i,n,x,y,tot,clock:longint;
12 ch:char;
13 procedure swap(var x,y:longint);inline;
14 var t:longint;
15 begin
16 t:=x;x:=y;y:=t;
17 end;
18 procedure insert(x,y:longint);inline;
19 begin
20 inc(tot);
21 e[tot].go:=y;e[tot].next:=head[x];head[x]:=tot;
22 end;
23 procedure dfs(x:longint);inline;
24 var i,y:longint;
25 begin
26 inc(clock);l[x]:=clock;
27 i:=head[x];
28 while i<>0 do
29 begin
30 y:=e[i].go;
31 if dep[y]=0 then
32 begin
33 dep[y]:=dep[x]+1;
34 dfs(y);
35 end;
36 i:=e[i].next;
37 end;
38 inc(clock);r[x]:=clock;
39 end;
40 procedure add(x,y:longint);inline;
41 begin
42 while x<=2*n do
43 begin
44 inc(s[x],y);
45 inc(x,x and (-x));
46 end;
47 end;
48 function sum(x:longint):longint;inline;
49 begin
50 sum:=0;
51 while x>0 do
52 begin
53 inc(sum,s[x]);
54 dec(x,x and (-x));
55 end;
56 end;
57 procedure init;
58 begin
59 readln(n);
60 for i:=1 to n-1 do begin readln(x,y);insert(x,y);insert(y,x);end;
61 dep[1]:=1;
62 dfs(1);
63 //for i:=1 to n do writeln(i,‘ ‘,l[i],‘ ‘,r[i],‘ ‘,dep[i]);
64 for i:=2 to n do begin add(l[i],1);add(r[i],-1);end;
65 end;
66 procedure solveask;inline;
67 begin
68 readln(x);writeln(sum(l[x]));
69 end;
70 procedure solvechange;inline;
71 begin
72 readln(x,y);
73 if dep[x]<dep[y] then swap(x,y);
74 add(l[x],-1);add(r[x],1);
75 end;
76 procedure main;
77 begin
78 readln;
79 while not eof do
80 begin
81 read(ch);
82 case ch of
83 ‘W‘:solveask;
84 ‘A‘:solvechange;
85 end;
86 end;
87 end;
88 begin
89 assign(input,‘input.txt‘);assign(output,‘output.txt‘);
90 reset(input);rewrite(output);
91 init;
92 main;
93 close(input);close(output);
94 end.