#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>

using namespace std;

typedef long long llint;

#define MAX 100000
#define LOG_MAX 17

int n, m, a, b;
int members[MAX];
int discover[MAX], finish[MAX], traversal_time = 0;
int depth[MAX];
int jump[MAX][LOG_MAX];
vector<int> adj[MAX];

void dfs( int i, int dad = -1 ) {
   jump[i][0] = dad;
   for( int p = 1; p < LOG_MAX; ++p )
      jump[i][p] = jump[i][p-1] != -1 ? jump[ jump[i][p-1] ][p-1] : -1;

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

int loga[MAX+1];
inline void update( int x, int delta ) {
   for( ; x <= n; x += x&-x ) loga[x] += delta;
}
int query( int x ) {
   int ret = 0;
   for( ; x > 0; x -= x&-x ) ret += loga[x];
   return ret;
}

int subtree_members( int i ) {
   return query( finish[i] ) - query( discover[i]-1 );
}

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

   for( int p = LOG_MAX-1; p >= 0; --p )
       if( ((depth[a]-depth[b])>>p)&1 ) 
           a = jump[a][p];       

   if( a == b ) return a;

   for( int p = LOG_MAX-1; p >= 0; --p )
      if( jump[a][p] != jump[b][p] ) { a = jump[a][p]; b = jump[b][p]; }

   return jump[a][0];
}

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

   depth[0] = 0;
   dfs( 0 );

   int prev = 0;
   llint total_members = 0, cost = 0;
   for( int i = 0; i < n; ++i ) {
      update( discover[i], members[i] );
      total_members += members[i];
      cost += (depth[i]-1) * members[i];
   }

   scanf( "%d", &m );
   for( int i = 0; i < m; ++i ) {
      char c; scanf( " %c%d", &c, &a ); --a;

      if( c == 'P' ) {
         update( discover[a], 1 );
         total_members += 1;
         cost += depth[prev]+depth[a] - 2*depth[lowest_common_ancestor(prev,a)];
      } else {
         if( prev == jump[a][0] ) cost += (total_members - 2*subtree_members(a));
         else                     cost -= (total_members - 2*subtree_members(prev));
         printf( "%lld\n", cost );
         prev = a;
      }
   }

   return 0;
}
