#include<bits/stdc++.h>
using namespace std;
const int N=30005;
struct node{
int to,nxt;
}e[N*2];
int head[N],cnt=1;
void add_edge(int x,int y)
{
e[++cnt].to=y,e[cnt].nxt=head[x],head[x]=cnt;
}
int dfn[N],w[N],clk,top[N],fa[N],maxson[N],sz[N],dep[N];
void dfs1(int x,int f)
{
sz[x]=1;
for(int i=head[x];i;i=e[i].nxt)
{
int y=e[i].to;
if(y==f)
{
continue;
}
fa[y]=x;
dep[y]=dep[x]+1;
dfs1(y,x);
sz[x]+=sz[y];
if(sz[maxson[x]]<sz[y])
{
maxson[x]=y;
}
}
}
void dfs2(int x,int f)
{
top[x]=f;
dfn[x]=++clk;
w[clk]=x;
if(!maxson[x])
{
return;
}
dfs2(maxson[x],f);
for(int i=head[x];i;i=e[i].nxt)
{
int y=e[i].to;
if(y==f or y==maxson[x])
{
continue;
}
dfs2(y,y);
}
}
int n,a[N],m;
struct node1{
int l,r,s,m;
}tr[N*4];
void updata(int root)
{
tr[root].l=tr[root*2].l;
tr[root].r=tr[root*2+1].r;
tr[root].s=tr[root*2].s+tr[root*2+1].s;
tr[root].m=max(tr[root*2].m,tr[root*2+1].m);
}
void build(int root,int l,int r)
{
if(l==r)
{
tr[root].s=tr[root].m=a[w[l]];
return;
}
int mid=(l+r)/2;
build(root*2,l,mid);
build(root*2+1,mid+1,r);
updata(root);
}
void change(int root,int l,int r,int p,int x)
{
if(l==r)
{
tr[root].s=tr[root].m=x;
return;
}
int mid=(l+r)/2;
if(p<=mid)
{
change(root*2,l,mid,p,x);
}
else if(p>mid)
{
change(root*2+1,mid+1,r,p,x);
}
updata(root);
}
int search_sum(int root,int l,int r,int x,int y)
{
if(l==x and r==y)
{
return tr[root].s;
}
int mid=(l+r)/2;
if(y<=mid)
{
return search_sum(root*2,l,mid,x,y);
}
else if(x>mid)
{
return search_sum(root*2+1,mid+1,r,x,y);
}
else
{
return search_sum(root*2,l,mid,x,mid)+search_sum(root*2+1,mid+1,r,mid+1,y);
}
}
int search_max(int root,int l,int r,int x,int y)
{
if(l==x and r==y)
{
return tr[root].m;
}
int mid=(l+r)/2;
if(y<=mid)
{
return search_max(root*2,l,mid,x,y);
}
else if(x>mid)
{
return search_max(root*2+1,mid+1,r,x,y);
}
else
{
return max(search_max(root*2,l,mid,x,mid),search_max(root*2+1,mid+1,r,mid+1,y));
}
}
string s;
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
cin>>n;
for(int i=1,x,y;i<n;i++)
{
cin>>x>>y;
add_edge(x,y);
add_edge(y,x);
}
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
dfs1(1ll,0);
dfs2(1ll,1ll);
build(1ll,1ll,n);
cin>>m;
for(int i=1,x,y;i<=m;i++)
{
cin>>s>>x>>y;
if(s=="CHANGE")
{
change(1ll,1ll,n,dfn[x],y);
}
else if(s=="QMAX")
{
int s=0;
while(top[x]!=top[y])
{
if(dep[top[x]]<dep[top[y]])
{
swap(x,y);
}
s=max(s,search_max(1ll,1ll,n,dfn[top[x]],dfn[x]));
x=fa[top[x]];
}
if(dep[x]<dep[y])
{
swap(x,y);
}
s=max(s,search_max(1ll,1ll,n,dfn[y],dfn[x]));
cout<<s<<'\n';
}
else if(s=="QSUM")
{
int s=0;
while(top[x]!=top[y])
{
if(dep[top[x]]<dep[top[y]])
{
swap(x,y);
}
s+=search_sum(1ll,1ll,n,dfn[top[x]],dfn[x]);
x=fa[top[x]];
}
if(dep[x]<dep[y])
{
swap(x,y);
}
s+=search_sum(1ll,1ll,n,dfn[y],dfn[x]);
cout<<s<<'\n';
}
else
{
cout<<"Error!";
}
}
return 0;
}