#include <algorithm>
#include <vector>
#include <string>

#include <cstdio>
#include <cstring>
#include <cmath>

using namespace std;

const int MAXN = 100100;
const int MAXLOG = 17;

int n, m, L;

int clanovi[ MAXN ];
vector< int > E[ MAXN ];
int depth[ MAXN ];

int tick = 1;
int D[ MAXN ];
int F[ MAXN ];

int dp[ MAXN ][ MAXLOG ];

long long fenwick[ 2*MAXN ];

void update( int x, long long val )
{
    for( ++x; x < 2*MAXN; x += x&-x )
        fenwick[x] += val;
}

long long query( int x )
{
    long long suma = 0;

    for( ++x; x > 0; x -= x&-x )
        suma += fenwick[x];

    return suma;
}

void dfs( int x, int dad )
{
    D[x] = tick++;
    dp[x][0] = dad;

    for( int i = 1; i < L; ++i )
        if( dp[x][i-1] == -1 )
            dp[x][i] = -1;
        else
            dp[x][i] = dp[ dp[x][i-1] ][ i-1 ];

    for( vector< int >::iterator it = E[x].begin(); it != E[x].end(); ++it ) {
        if( *it == dad ) continue;
        depth[*it] = depth[x] + 1;
        dfs( *it, x );
    }

    F[x] = tick++;
}

pair< long long, int > solve( int x, int dad )
{
    pair< long long, int > ret( 0LL, clanovi[x] );

    for( vector< int >::iterator it = E[x].begin(); it != E[x].end(); ++it ) {
        if( *it == dad ) continue;
        pair< long long, int > p = solve( *it, x );
        ret.first += p.first + p.second;
        ret.second += p.second;
    }

    return ret;
}

int lca( int a, int b )
{
    if( depth[a] < depth[b] ) swap( a, b );

    for( int i = L-1; i >= 0; --i )
        if( depth[a] - (1<<i) >= depth[b] )
            a = dp[a][i];

    if( a == b ) return a;

    for( int i = L-1; i >= 0; --i )
        if( dp[a][i] != dp[b][i] )
            a = dp[a][i], b = dp[b][i];

    return dp[a][0];
}

inline long long subtree( int x )
{
    return query( F[x] ) - query( D[x]-1 );
}

inline int dist( int a, int b )
{
    return depth[a] + depth[b] - 2 * depth[ lca( a, b ) ];
}

int main( void )
{
    scanf( "%d", &n );
    for( L = 1; (1<<L) < n; ++L );

    long long cnt = 0;

    for( int i = 0; i < n; ++i ) {
        scanf( "%d", clanovi + i );
        cnt += clanovi[i];
    }

    for( int i = 1; i < n; ++i ) {
        int a, b; scanf( "%d %d", &a, &b ); --a, --b;
        E[a].push_back( b );
        E[b].push_back( a );
    }

    dfs( 0, -1 );

    for( int i = 0; i < n; ++i )
        update( D[i], clanovi[i] );

    scanf( "%d", &m );

    long long cost = 0;
    int last = -1;

    for( ; m > 0; --m ) {
        char tip[5]; scanf( "%s", tip );
        int x; scanf( "%d", &x ); --x;

        if( *tip == 'P' ) {
            ++cnt;
            update( D[x], 1 );
            cost += dist( x, last );
        }
        else {
            if( last == -1 )
                cost = solve( 0, -1 ).first;
            else if( D[last] < D[x] )
                cost = cost + cnt - 2 * subtree( x );
            else
                cost = cost - cnt + 2 * subtree( last );

            last = x;
            printf( "%lld\n", cost );
        }
    }

    return 0;
}

