#include <cstring>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <fstream>
#include <iostream>
#define rep(i, l, r) for(int i = l; i <= r; i++)
#define down(i, l, r) for(int i = l; i >= r; i--)
#define MS 99999
#define MAX 1037471823
#define Q 1
using namespace std;
struct edge { int y, n; } e[ MS] ; int ec, f[ MS] ;
int tl[ MS] , tr[ MS] , ts[ MS] , tn[ MS] , tc, tb[ MS] ;
int lb[ MS] , ld[ MS] , lr[ MS] , ls[ MS] , lh[ MS] , ln;
int n, w[ MS] , s[ MS] , d[ MS] , h[ MS] , m, x, y, ans;
char q[ 10 ] ;
void Search( int x, int n)
{
int o = f[ x] , m = 0 , my = 0 , y = e[ o] .y ; s[ x] = 1 ; d[ x] = n;
while ( y) { if ( y ! = h[ x] ) { h[ y] = x; Search( y, n+ 1 ) ; s[ x] + = s[ y] ; if ( m < s[ y] ) m = s[ y] , my = y; } o = e[ o] .n , y = e[ o] .y ; }
o = f[ x] , y = e[ o] .y ; while ( y) { if ( y ! = h[ x] && y ! = my) { ls[ lb[ y] ] = lr[ y] , ld[ lb[ y] ] = n+ 1 , lh[ lb[ y] ] = x; } o = e[ o] .n , y = e[ o] .y ; }
if ( my) lb[ x] = lb[ my] , lr[ x] = lr[ my] + 1 ; else ln++ , lb[ x] = ln, lr[ x] = 1 ;
}
void Build( int l, int r, int o) { if ( l == r) return ; int m = ( l+ r) / 2 ; tl[ o] = ++ tc; Build( l, m, tc) ; tr[ o] = ++ tc; Build( m+ 1 , r, tc) ; }
void Edit( int x, int l, int r, int o)
{
if ( l == r) ts[ o] = tn[ o] = w[ x] ;
else
{
int m = ( l+ r) / 2 ;
if ( lr[ x] <= m) Edit( x, l, m, tl[ o] ) ; else Edit( x, m+ 1 , r, tr[ o] ) ;
ts[ o] = ts[ tl[ o] ] + ts[ tr[ o] ] ; tn[ o] = max( tn[ tl[ o] ] , tn[ tr[ o] ] ) ;
}
}
void TQMax( int l, int r, int o) { if ( x <= l && r <= y) ans = max( ans, tn[ o] ) ; else { int m = ( l+ r) / 2 ; if ( x <= m) TQMax( l, m, tl[ o] ) ; if ( m+ 1 <= y) TQMax( m+ 1 , r, tr[ o] ) ; } }
void TQSum( int l, int r, int o) { if ( x <= l && r <= y) ans + = ts[ o] ; else { int m = ( l+ r) / 2 ; if ( x <= m) TQSum( l, m, tl[ o] ) ; if ( m+ 1 <= y) TQSum( m+ 1 , r, tr[ o] ) ; } }
void QMax( int a, int b)
{
while ( lb[ a] ! = lb[ b] )
{ if ( ld[ lb[ a] ] <= ld[ lb[ b] ] ) x = a, a = b, b = x; x = lr[ a] , y = ls[ lb[ a] ] ; TQMax( 1 , ls[ lb[ a] ] , tb[ lb[ a] ] ) ; a = lh[ lb[ a] ] ; }
x = min( lr[ a] , lr[ b] ) ; y = max( lr[ a] , lr[ b] ) ; TQMax( 1 , ls[ lb[ a] ] , tb[ lb[ a] ] ) ;
}
void QSum( int a, int b)
{
while ( lb[ a] ! = lb[ b] )
{ if ( ld[ lb[ a] ] <= ld[ lb[ b] ] ) x = a, a = b, b = x; x = lr[ a] , y = ls[ lb[ a] ] ; TQSum( 1 , ls[ lb[ a] ] , tb[ lb[ a] ] ) ; a = lh[ lb[ a] ] ; }
x = min( lr[ a] , lr[ b] ) ; y = max( lr[ a] , lr[ b] ) ; TQSum( 1 , ls[ lb[ a] ] , tb[ lb[ a] ] ) ;
}
int main( )
{
scanf ( "%d" , & n) ;
rep( i, 1 , n- 1 )
{ scanf ( "%d%d" , & x, & y) ; e[ ++ ec] .y = y, e[ ec] .n = f[ x] , f[ x] = ec, e[ ++ ec] .y = x, e[ ec] .n = f[ y] , f[ y] = ec; }
rep( i, 1 , n) scanf ( "%d" , & w[ i] ) ;
Search( 1 , 0 ) ; ls[ lb[ 1 ] ] = lr[ 1 ] , ld[ lb[ 1 ] ] = 0 , lh[ lb[ 1 ] ] = 0 ;
rep( i, 1 , ln) { tb[ i] = ++ tc; Build( 1 , ls[ i] , tb[ i] ) ; } tn[ 0 ] = - MAX;
rep( i, 1 , n) Edit( i, 1 , ls[ lb[ i] ] , tb[ lb[ i] ] ) ;
scanf ( "%d" , & m) ; rep( i, 1 , m)
{
scanf ( "%s%d%d" , q, & x, & y) ;
if ( q[ 1 ] == 'M' ) { ans = - MAX; QMax( x, y) ; printf ( "%d\n " , ans) ; }
else if ( q[ 1 ] == 'S' ) { ans = 0 ; QSum( x, y) ; printf ( "%d\n " , ans) ; }
else { w[ x] = y; Edit( x, 1 , ls[ lb[ x] ] , tb[ lb[ x] ] ) ; }
}
}
I2luY2x1ZGUgPGNzdHJpbmc+CiNpbmNsdWRlIDxjbWF0aD4KI2luY2x1ZGUgPGNzdGRsaWI+CiNpbmNsdWRlIDxjc3RkaW8+CiNpbmNsdWRlIDxhbGdvcml0aG0+CiNpbmNsdWRlIDxmc3RyZWFtPgojaW5jbHVkZSA8aW9zdHJlYW0+CgojZGVmaW5lIHJlcChpLCBsLCByKSBmb3IoaW50IGkgPSBsOyBpIDw9IHI7IGkrKykKI2RlZmluZSBkb3duKGksIGwsIHIpIGZvcihpbnQgaSA9IGw7IGkgPj0gcjsgaS0tKQojZGVmaW5lIE1TIDk5OTk5CiNkZWZpbmUgTUFYIDEwMzc0NzE4MjMKI2RlZmluZSBRIDEKCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgpzdHJ1Y3QgZWRnZSB7IGludCB5LCBuOyB9IGVbTVNdOyBpbnQgZWMsIGZbTVNdOwppbnQgdGxbTVNdLCB0cltNU10sIHRzW01TXSwgdG5bTVNdLCB0YywgdGJbTVNdOwppbnQgbGJbTVNdLCBsZFtNU10sIGxyW01TXSwgbHNbTVNdLCBsaFtNU10sIGxuOwppbnQgbiwgd1tNU10sIHNbTVNdLCBkW01TXSwgaFtNU10sIG0sIHgsIHksIGFuczsKY2hhciBxWzEwXTsKCnZvaWQgU2VhcmNoKGludCB4LCBpbnQgbikKewoJaW50IG8gPSBmW3hdLCBtID0gMCwgbXkgPSAwLCB5ID0gZVtvXS55OyBzW3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