#include<iostream>
#include<vector>
#include<set>

using namespace std;


int cnt=0;
int p[100010][21];
int c[100010];
int ord[100010];
int invord[100010];
int h[100010];
int ans[100010];
vector<int> g[100010];
set<int>  st[100010];
int sm[100010];
void dfs(int now,int prev){
    if(ord[now]==-1){
        ord[now] = cnt;
        cnt++;
    }
    if(prev!=-1){
        h[now] = h[prev]+1;
        p[now][0] = prev;
    }
    for(auto x:g[now]){
        if(x!=prev){
            dfs(x,now);
        }
    }
}

int lca(int a,int b){
    if(h[a]>h[b])swap(a,b);
    for(int i=0;i<21;i++){
        if(((h[b]-h[a])>>i) & 1){
            b = p[b][i];
        }
    }
    if(a==b)return a;
    for(int i=20;i>=0;i--){
        if(p[a][i]!=p[b][i]){
            a = p[a][i];
            b = p[b][i];
        }
    }
    
    return p[a][0];
}


int main(){
    int n;
    cin >> n;
    for(int i=0;i<n-1;i++){
        int a,b;
        cin >> a >> b;
        a--;
        b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    for(int i=0;i<n;i++){
        ord[i] = -1;
    }
    h[0]=0;
    dfs(0,-1);
    p[0][0]= 0;
    for(int i=1;i<21;i++){
        for(int j=0;j<n;j++){
            p[j][i] = p[p[j][i-1]][i-1];
        }
    }
    for(int i=0;i<n;i++){
        invord[ord[i]] = i; 
    }
    for(int i=0;i<n;i++){
        cin >> c[i];
        if(st[c[i]].size()==0){
            st[c[i]].insert(ord[i]);
        }else if(st[c[i]].size()==1){
            auto x = st[c[i]].begin();
            int q = *x;
            int k = lca(invord[q],i);
            ans[c[i]] += h[i]-h[k];
            ans[c[i]] += h[invord[q]]-h[k];
            st[c[i]].insert(ord[i]);
        }else{
            auto x = st[c[i]].lower_bound(ord[i]);
            int k=-1;
            if(x!=st[c[i]].end()){
                int q = *x;
                k = lca(invord[q],i);
            }
            if(x!=st[c[i]].begin()){
                x--;
                int q = *x;
                int r = lca(invord[q],i);
                if(k==-1){
                    k = r;
                }else if(h[k]<h[r]){
                    k = r;
                } 
            }
            auto ppp = st[c[i]].begin();
            auto qqq = st[c[i]].end();
            qqq--;
            int hi = lca(invord[*ppp],invord[*qqq]);
            if(h[hi]>h[k]){
                ans[c[i]]+=h[hi]-h[k];
                ans[c[i]]+=h[i]-h[k];
            }else{
                ans[c[i]]+=h[i]-h[k];
            }
            st[c[i]].insert(ord[i]);
        }
    }
    int q;
    cin >> q;
    for(int tt=0;tt<q;tt++){
        char ch;
        cin >> ch;
        if(ch=='Q'){
            int a;
            cin >> a;
            if(st[a].size()==0){
                cout << -1 << endl;
            }else{
                cout << ans[a] << endl;
            }
        }else{
            int a,b;
            cin >> a >> b;
            a--;
            st[c[a]].erase(ord[a]);
            if(st[c[a]].size()<=1){
                ans[c[a]] = 0;   
            }else{
                auto x = st[c[a]].lower_bound(ord[a]);
                int k=-1;
                if(x!=st[c[a]].end()){
                    int q = *x;
                    k = lca(invord[q],a);
                }
                if(x!=st[c[a]].begin()){
                    x--;
                    int q = *x;
                    int r = lca(invord[q],a);
                    if(k==-1||h[k]<h[r]){
                        k = r;
                    } 
                }
                auto ppp = st[c[a]].begin();
                auto qqq = st[c[a]].end();
                qqq--;
                int hi = lca(invord[*ppp],invord[*qqq]);
                if(h[hi]>h[k]){
                    ans[c[a]]-=h[hi]-h[k];
                    ans[c[a]]-=h[a]-h[k];
                }else{
                    ans[c[a]]-=h[a]-h[k];
                }

            }
            //cerr << c[a] << " " << ans[c[a]] << endl;
            
            c[a] = b;
            if(st[b].size()==0){

            }else if(st[b].size()==1){
                int k;
                auto x = st[c[a]].begin();
                int q = *x;
                k = lca(invord[q],a);
                ans[b] +=  h[invord[q]]-h[k];
                ans[b] += h[a]-h[k];
            }else{
                int k;
                auto x = st[c[a]].lower_bound(ord[a]);
                k = -1;
                if(x!=st[c[a]].end()){
                    int q = *x;
                    k = lca(invord[q],a);
                }
                if(x!=st[c[a]].begin()){
                    x--;
                    int q = *x;
                    int r = lca(invord[q],a);
                    if(k==-1||h[k]<h[r]){
                        k = r;
                    } 
                }
                auto ppp = st[c[a]].begin();
                auto qqq = st[c[a]].end();
                qqq--;
                int hi = lca(invord[*ppp],invord[*qqq]);
                if(h[hi]>h[k]){
                    ans[c[a]]+=h[hi]-h[k];
                    ans[c[a]]+=h[a]-h[k];
                }else{
                    ans[c[a]]+=h[a]-h[k];
                }


            }
            st[b].insert(ord[a]);
            //cerr << b << " " << ans[b] << endl;
        }

    }
    return 0;
}


Measured memory_bytes: 32284