#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define SIZE 100005


int N;
int root,global_index;
int MAX_LOG_V = 17;
int POW[18],depth[SIZE],COLOR[SIZE],index_table[SIZE];
int parent[18][SIZE];
int LCA[SIZE],num_Edges[SIZE];
set<int> SET[SIZE];
vector<int> first_G[SIZE],G[SIZE];

void dfs(int node_id,int parent_id,int d){
    parent[0][node_id] = parent_id;
    depth[node_id] = d;
    for(int i = 0; i < G[node_id].size(); i++){
        if(G[node_id][i] != parent_id)dfs(G[node_id][i],node_id,d+1);
    }
}

void init(){

    dfs(root,-1,0);

    for(int k = 0; k + 1 < MAX_LOG_V; k++){
        for(int node_id = 0; node_id < N; node_id++){
            if(parent[k][node_id] < 0)parent[k+1][node_id] = -1;
            else{
                parent[k+1][node_id] = parent[k][parent[k][node_id]];
            }
        }
    }
}


int lca(int left,int right){

    if(depth[left] > depth[right])swap(left,right);

    for(int k = MAX_LOG_V-1; k >= 0; k--){
        if(depth[right]-depth[left] >= POW[k]){
            right = parent[k][right];
        }
    }

    if(left == right)return left;

    for(int k = MAX_LOG_V-1; k >= 0; k--){
        if(parent[k][left] == parent[k][right]){
            //Do nothing
        }else{
            left = parent[k][left];
            right = parent[k][right];
        }
    }
    return parent[0][left];
}

void pre_order_dfs(int node_id,int pre){

    index_table[node_id] = global_index++;

    if(pre != -1){

        G[index_table[pre]].push_back(index_table[node_id]);
    }

    for(int i = 0; i < first_G[node_id].size(); i++){

        if(first_G[node_id][i] == pre)continue;

        pre_order_dfs(first_G[node_id][i],node_id);
    }
}

void add_node(int node_id,int color){

    if(SET[color].size() == 0){

    	SET[color].insert(node_id);
        LCA[color] = node_id;
        num_Edges[color] = 0;

        return;
    }

    int new_lca = lca(node_id,LCA[color]);

    if(new_lca != LCA[color]){ //lcaが変わる場合

        num_Edges[color] += (depth[node_id]+depth[LCA[color]]-2*depth[new_lca]);
        LCA[color] = new_lca;

    }else{ //lcaが変わらない場合

        auto at = SET[color].lower_bound(node_id);

        int add = BIG_NUM;

        //近い方を採用
        if(at != SET[color].end()){ //node_id以上の、最小番号を持つ頂点との計算

            int tmp_lca = lca(node_id,*at);
            add = depth[node_id]-depth[tmp_lca];
        }
        if(at != SET[color].begin()){ //node_id未満の、最大番号を持つ頂点との計算
            at--;

            int tmp_lca = lca(node_id,*at);
            add = min(add,depth[node_id]-depth[tmp_lca]);
        }

        if(add != BIG_NUM){

            num_Edges[color] += add;
        }
    }

    SET[color].insert(node_id);
}

void delete_node(int node_id,int color){

	SET[color].erase(node_id);

	if(SET[color].size() == 0){

		num_Edges[color] = -1;
		return;
	}

	auto at = SET[color].begin();
	int A = *at;
	at = SET[color].end();
	at--;
	int B = *at;

	int new_lca = lca(A,B);

	if(new_lca != LCA[color]){ //LCAが変わる場合

		num_Edges[color] -= (depth[node_id]+depth[new_lca]-2*depth[LCA[color]]);
		LCA[color] = new_lca;

	}else{ //LCAが変わらない場合

		auto at = SET[color].lower_bound(node_id);

		int minus = BIG_NUM;

		//近い方を採用
		if(at != SET[color].end()){ //node_id以上の、最小番号を持つ頂点との計算

			int tmp_lca = lca(node_id,*at);
			minus = depth[node_id]-depth[tmp_lca];
		}
		if(at != SET[color].begin()){ //node_id未満の、最大番号を持つ頂点との計算
			at--;

			int tmp_lca = lca(node_id,*at);
			minus = min(minus,depth[node_id]-depth[tmp_lca]);
		}

		if(minus != BIG_NUM){

			num_Edges[color] -= minus;
		}
	}
}

int main(){

    POW[0] = 1;
    for(int i = 1; i <= 17; i++){

        POW[i] = POW[i-1]*2;
    }

    scanf("%d",&N);

    int from,to;

    for(int loop = 0; loop < N-1; loop++){

        scanf("%d %d",&from,&to);
        from--;
        to--;

        first_G[from].push_back(to);
        first_G[to].push_back(from);
    }

    for(int i = 0; i < N; i++){

        scanf("%d",&COLOR[i]);
        COLOR[i]--;
    }

    //pre-orderに番号を振る
    global_index = 0;
    pre_order_dfs(0,-1);

    //LCA木の構築
    root = 0;
    init();


    for(int i = 0; i < SIZE; i++){

        num_Edges[i] = -1;
    }

    //状態を初期化
    for(int i = 0; i < N; i++){

        add_node(index_table[i],COLOR[i]);
    }

    int num_query;
    scanf("%d",&num_query);

    char command[2];
    int x,y;

    for(int loop = 0; loop < num_query; loop++){

        scanf("%s",command);

        if(command[0] == 'U'){

            scanf("%d %d",&x,&y);
            x--;
            y--;

            delete_node(index_table[x],COLOR[x]); //x == yの場合対策
            add_node(index_table[x],y);

            COLOR[x] = y;

        }else{

            scanf("%d",&y);
            y--;

            printf("%d\n",num_Edges[y]);
        }
    }

    return 0;
}



Measured memory_bytes: 37812