#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

int par[MAX_N][18];

template<typename T> class segtree {
private:
    int n,sz;
    vector<pair<T, int> > node;
public:
    void resize(vector<T>& v){
        sz = (int)v.size();
        n = 1;
        while(n < sz){
            n *= 2;
        }
        node.resize(2*n);
        rep(i,sz){
            node[i+n] = make_pair(v[i], i);
        }
        for(int i=n-1; i>=1; i--){
            node[i] = min(node[2*i], node[2*i+1]);
        }
    }
    void update(int k, T a)
    {
    	node[k+=n] = make_pair(a, k);
    	while(k>>=1){
            node[k] = min(node[2*k], node[2*k+1]);
    	}
    }
    pair<T, int> query(int a,int b)
    {
        pair<T, int> res1 = make_pair(numeric_limits<T>::max(), -1);
        pair<T, int> res2 = make_pair(numeric_limits<T>::max(), -1);
        a += n, b += n;
        while(a != b){
            if(a % 2) cmn(res1, node[a++]);
            if(b % 2) cmn(res2, node[--b]);
            a >>= 1, b>>= 1;
        }
        return min(res1, res2);
    }
};

class LCA {
public:
    vector<int> ord,depth,id;
    vector<int> in,out;
    vector<vector<int> > G;
    segtree<int> st;
    int V;
    LCA(int node_size){
        V = node_size;
        G.resize(V),depth.resize(V),id.resize(V,-1),in.resize(V,-1),out.resize(V,-1);
    }
    void add_edge(int from,int to){
        G[from].push_back(to),G[to].push_back(from);
    }
    void dfs(int u,int p,int k,int& tm){
        par[u][0] = p;
        id[u] = (int)ord.size();
        in[u] = tm;
        ord.push_back(u);
        depth[u] = k;
        rep(i,G[u].size()){
            if(G[u][i] != p){
                dfs(G[u][i],u,k+1,++tm);
                ord.push_back(u);
            }
        }
        out[u] = tm+1;
    }
    void build(){
        int tm = 0;
        rep(i,V){
            if(id[i] < 0){
                dfs(i,-1,0,tm);
            }
        }
        rep(j,17){
            rep(i,V){
                if(par[i][j] < 0){
                    par[i][j+1] = -1;
                }else{
                    par[i][j+1] = par[par[i][j]][j];
                }
            }
        }
        vector<int> stvec((int)ord.size());
    	rep(i,ord.size()){
    		stvec[i] = depth[ord[i]];
    	}
        st.resize(stvec);
    }
    int solve(int u,int v){
        return ord[st.query(min(id[u],id[v]),max(id[u],id[v])+1).second];
    }
    int dist(int u,int v){
        int lca = solve(u,v);
        return depth[u] + depth[v] - 2*depth[lca];
    }
};

set<int> st[MAX_N], ver[MAX_N];
int cs[MAX_N], root[MAX_N], color[MAX_N];

// u 以下に色 cl の頂点があるか
bool exist(int u, int cl, vi& in, vi& out)
{
    auto it = st[cl].lower_bound(in[u]);
    return (it != st[cl].end() && *it < out[u]);
}

void insert(int u, int cl, vi& in, vi& out, vvi& G, LCA& lca)
{
    ver[cl].insert(u);
    if(len(ver[cl]) == 1){
        root[cl] = u;
        st[cl].insert(in[u]);
        return;
    }
    int p = lca.solve(u, root[cl]);
    if(p != root[cl]){
        cs[cl] += lca.dist(root[cl], u);
        root[cl] = p;
        st[cl].insert(in[u]);
        return;
    }
    // 下にある
    if(exist(u, cl, in, out)){
        st[cl].insert(in[u]);
        return;
    }
    int nw = u, dist = 0;
    rrep(i,18){
        if(par[nw][i] < 0) continue;
        if(!exist(par[nw][i],cl,in,out)){
            nw = par[nw][i];
            dist += (1 << i);
        }
    }
    cs[cl] += dist + 1;
    st[cl].insert(in[u]);
}

bool exist2(int u, int cl, vi& in, vi& out){
    auto it = st[cl].lower_bound(in[u]);
    auto it2 = st[cl].lower_bound(out[u]);
    return (it != st[cl].begin() || it2 != st[cl].end());
}

void erase(int u, int cl, vi& in, vi& out, vvi& G, LCA& lca, vi& dep){
    ver[cl].erase(u);
    st[cl].erase(in[u]);
    if(len(ver[cl]) == 0) return;
    if(exist(u,cl,in,out) && root[cl] != u) return;
    if(!exist(u,cl,in,out)){
        // 下から上がってぶつかる位置
        int nw1 = u, depth = 0;
        rrep(i,18){
            if(par[nw1][i] < 0) continue;
            if(!exist(par[nw1][i],cl,in,out)){
                nw1 = par[nw1][i];
                depth += (1 << i);
            }
        }
        // 根の位置
        int nw2 = *ver[cl].begin();
        if(!exist2(nw2,cl,in,out)){
            root[cl] = nw2;
        }else{
            rrep(i,18){
                if(par[nw2][i] < 0) continue;
                if(exist2(par[nw2][i],cl,in,out)){
                    nw2 = par[nw2][i];
                }
            }
            root[cl] = par[nw2][0];
        }
        if(dep[nw1] > dep[root[cl]]){
            cs[cl] -= depth + 1;
        }else{
            cs[cl] -= lca.dist(u,root[cl]);
        }
        return;
    }
    int nw = *ver[cl].begin();
    if(!exist2(nw,cl,in,out)){
        root[cl] = nw;
    }else{
        rrep(i,18){
            if(par[nw][i] < 0) continue;
            if(exist2(par[nw][i],cl,in,out)){
                nw = par[nw][i];
            }
        }
        root[cl] = par[nw][0];
    }
    cs[cl] -= lca.dist(u, root[cl]);
    return;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    LCA lca(n);
    rep(i,n-1){
        int a,b;
        cin >> a >> b;
        lca.add_edge(a-1, b-1);
    }
    lca.build();
    auto& G = lca.G;
    auto& in = lca.in;
    auto& out = lca.out;
    auto& depth = lca.depth;
    rep(i,n){
        int a;
        cin >> a;
        insert(i,a-1,in,out,G,lca);
        color[i] = a-1;
    }
    // sar(cs, n);
    int m;
    cin >> m;
    rep(i,m){
        string c;
        cin >> c;
        if(c == "U"){
            int x,y;
            cin >> x >> y;
            erase(x-1,color[x-1],in,out,G,lca,depth);
            insert(x-1,y-1,in,out,G,lca);
            color[x-1] = y-1;
            // sar(cs, n);
        }else{
            int x;
            cin >> x;
            if(len(ver[x-1]) == 0){
                cout << "-1\n";
            }else{
                cout << cs[x-1] << "\n";
            }
        }
    }
    return 0;
}


Measured memory_bytes: 43936