#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
const int M=1e7+10;
int w[N],c[N],last[N*2],s[17],root[N];
int son[N],deep[N],dfn[N],top[N],fa[N][17];
int mx[M],sum[M],ls[M],rs[M];
int n,q,cnt,tim,tot;
struct orz{
int v,next;}e[N*2];
void add(int x,int y)
{
cnt++;
e[cnt].v=y;
e[cnt].next=last[x];
last[x]=cnt;
}
void dfs1(int x)
{
son[x]=1;
for (int i=1;i<=16;i++)
{
if (s[i]<=deep[x]) fa[x][i]=fa[fa[x][i-1]][i-1];
else break;
}
for (int i=last[x];i;i=e[i].next)
{
int v=e[i].v;
if (v==fa[x][0]) continue;
deep[v]=deep[x]+1;
fa[v][0]=x;
dfs1(v);
son[x]+=son[v];
}
}
void dfs2(int x,int chain)
{
tim++;
dfn[x]=tim;
top[x]=chain;
int k=0;
for (int i=last[x];i;i=e[i].next)
{
if (deep[e[i].v]>deep[x] && son[e[i].v]>son[k])
k=e[i].v;
}
if (k) dfs2(k,chain);
for (int i=last[x];i;i=e[i].next)
{
if (deep[e[i].v]>deep[x] && e[i].v!=k)
dfs2(e[i].v,e[i].v);
}
}
int lca(int x,int y)
{
if (deep[x]<deep[y]) swap(x,y);
int t=deep[x]-deep[y];
for (int i=0;i<=16;i++)
if (s[i]&t) x=fa[x][i];
for (int i=16;i>=0;i--)
if (fa[x][i]!=fa[y][i]) x=fa[x][i],y=fa[y][i];
if (x==y) return x;
return fa[x][0];
}
//===========================================================
void PushUp(int s)
{
mx[s]=max(mx[ls[s]],mx[rs[s]]);
sum[s]=sum[ls[s]]+sum[rs[s]];
}
void change(int &s,int l,int r,int pos,int val)
{
if (!s) s=++tot;
if (l==r)
{
mx[s]=sum[s]=val;
return ;
}
int mid=(l+r)>>1;
if (pos<=mid) change(ls[s],l,mid,pos,val);
else change(rs[s],mid+1,r,pos,val);
PushUp(s);
}
int querysum(int s,int l,int r,int L,int R)
{
if (!s) return 0;
if (L<=l&&r<=R) return sum[s];
int mid=(l+r)>>1;
int ret=0;
if (L<=mid) ret+=querysum(ls[s],l,mid,L,R);
if (R>mid) ret+=querysum(rs[s],mid+1,r,L,R);
return ret;
}
int querymx(int s,int l,int r,int L,int R)
{
if (!s) return 0;
if (L<=l&&r<=R) return mx[s];
int mid=(l+r)>>1;
int ret=0;
if (L<=mid) ret=max(ret,querymx(ls[s],l,mid,L,R));
if (R>mid) ret=max(ret,querymx(rs[s],mid+1,r,L,R));
return ret;
}
//===========================================================
int solvesum(int c,int x,int y)
{
int ret=0;
while (top[x]!=top[y]) //因为在这题中y是x的祖先所以不用考虑x和y的深度关系
{
ret+=querysum(root[c],1,n,dfn[top[x]],dfn[x]);
x=fa[top[x]][0];
}
ret+=querysum(root[c],1,n,dfn[y],dfn[x]);
return ret;
}
int solvemx(int c,int x,int y)
{
int mx=0;
while (top[x]!=top[y])
{
mx=max(mx,querymx(root[c],1,n,dfn[top[x]],dfn[x]));
x=fa[top[x]][0];
}
mx=max(mx,querymx(root[c],1,n,dfn[y],dfn[x]));
return mx;
}
//===========================================================
void pre()
{
s[0]=1;
for (int i=1;i<=16;i++) s[i]=s[i-1]*2;
}
int main()
{
pre();
scanf("%d%d",&n,&q);
for (int i=1;i<=n;i++)scanf("%d%d",&w[i],&c[i]);
int x,y;
for (int i=1;i<n;i++)
{
scanf("%d%d",&x,&y);
add(x,y); add(y,x);
}
dfs1(1); dfs2(1,1);
for (int i=1;i<=n;i++)
change(root[c[i]],1,n,dfn[i],w[i]);
char op[5];
while (q--)
{
scanf("%s",op);
scanf("%d%d",&x,&y);
if (op[0]==‘C‘)
{
if (op[1]==‘C‘)
{
change(root[c[x]],1,n,dfn[x],0);
c[x]=y;
change(root[c[x]],1,n,dfn[x],w[x]);
}
else
{
change(root[c[x]],1,n,dfn[x],y);
w[x]=y;
}
}
else
{
int f=lca(x,y);
if (op[1]==‘S‘)
{
int t=solvesum(c[x],x,f)+solvesum(c[x],y,f);g
if (c[x]==c[f]) t-=w[f];
printf("%d\n",t);
}
else
{
int t=max(solvemx(c[x],x,f),solvemx(c[x],y,f));
printf("%d\n",t);
}
}
}
return 0;
}