/*
Author:wuhuajun
*/
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#define lson l, mid, seg[rt].l
#define rson mid+1, r, seg[rt].r
using namespace std;
typedef long long ll;
typedef double dd;
const int maxn=200010;
const int maxq = 20000010;
int edge, n, fa[maxn], sz[maxn], son[maxn], dep[maxn], hash[maxn], top[maxn];
int h[maxn], num , x, y, tx, ty, Q, a[maxn], b[maxn], node, rel;
char s[22];
struct Edge
{
int to, ne;
} e[maxn * 2];
struct Seg
{
int maxx, sum, l, r;
void clear()
{
maxx = -1000000000;
sum = 0;
}
} seg[maxq], ret, ans;
void close()
{
exit(0);
}
void addedge(int x,int y)
{
e[edge].to = y;
e[edge].ne = h[x];
h[x] = edge++;
}
void dfs(int k,int from)
{
sz[k] = 1;
son[k] = 0;
dep[k] = dep[from] + 1;
for (int p=h[k];p!=-1;p=e[p].ne)
{
int to = e[p].to;
if (from == to) continue;
fa[to] = k;
dfs(to, k);
sz[k] += sz[to];
if (sz[to] > sz[son[k]]) son[k] = to;
}
}
void build(int k,int from)
{
hash[k] = ++num;
top[k] = from;
if (son[k]) build(son[k], from);
for (int p=h[k];p!=-1;p=e[p].ne)
{
int to = e[p].to;
if (to != fa[k] && to != son[k])
build(to, to);
}
}
//{{{Segment部分
void new_node(int rt)
{
if (seg[rt].l == 0) seg[rt].l = ++node;
if (seg[rt].r == 0) seg[rt].r = ++node;
}
Seg update(Seg a,Seg b)
{
Seg c;
c.sum = a.sum + b.sum;
c.maxx = max(a.maxx, b.maxx);
return c;
}
void pushup(int rt)
{
seg[rt].maxx = max(seg[seg[rt].l].maxx, seg[seg[rt].r].maxx);
seg[rt].sum = seg[seg[rt].l].sum + seg[seg[rt].r].sum;
}
void change(int L,int R,int val,int l,int r,int rt)
{
new_node(rt);
if (L <= l && r <= R)
{
seg[rt].sum = seg[rt].maxx = val;
return;
}
int mid = (l + r) >> 1;
if (L <= mid)
change(L,R,val,lson);
if (mid + 1 <= R)
change(L,R,val,rson);
pushup(rt);
}
Seg query(int L,int R,int l,int r,int rt)
{
new_node(rt);
if (L <= l && r <= R)
{
return seg[rt];
}
int mid = (l + r) >> 1;
Seg ans;
ans.clear();
if (L <= mid)
ans = update(ans, query(L,R,lson));
if (mid + 1 <= R)
ans = update(ans, query(L,R,rson));
return ans;
}
//}}}
Seg get_ans()
{
tx = top[x];
ty = top[y];
ans.clear();
while (tx != ty)
{
if (dep[tx] < dep[ty])
{
swap(tx, ty);
swap(x, y);
}
ans = update(ans, query(hash[tx], hash[x], 1, n, rel));
x = fa[tx];
tx = top[x];
}
if (dep[x] > dep[y]) swap(x, y);
return update(ans, query(hash[x], hash[y], 1, n, rel));
}
void init()
{
scanf("%d %d",&n, &Q);
memset(h,-1,sizeof(h));
for (int i=1;i<=n;i++)
{
scanf("%d %d",&b[i], &a[i]);
}
for (int i=1;i<=n-1;i++)
{
scanf("%d %d",&x, &y);
addedge(x, y);
addedge(y, x);
}
for (int i=1;i<=n;i++)
scanf("%d", &a[i]);
dfs(1, 0);
build(1, 1);
node = n;
/*
for (int i=1;i<=n;i++)
{
printf("i:%d top:%d hash:%d\n",i, top[i], hash[i]);
}
*/
for (int i=1;i<=n;i++)
change(hash[i], hash[i], b[i], 1, n, a[i]); // a -> 宗教 b -> 评级
while (Q--)
{
scanf("%s %d %d", s, &x, &y);
if (s[1] == ‘C‘)
{
change(hash[x], hash[x], 0, 1, n, a[x]); //把本属于宗教a[i]的x点评级改成0;
a[x] = y;
change(hash[x], hash[x], b[x], 1, n, a[x]); //把本属于宗教a[i]的x点评级改成现有的
}
if (s[1] == ‘W‘)
{
b[x] = y;
change(hash[x], hash[x], y, 1, n, a[x]);
}
if (s[1] == ‘S‘)
{
rel = a[x];
ret = get_ans();
printf("%d\n", ret.sum);
}
if (s[1] == ‘M‘)
{
rel = a[x];
ret = get_ans();
printf("%d\n", ret.maxx);
}
}
}
int main ()
{
init();
close();
return 0;
}