#include <bits/stdc++.h>
#define PII pair<int, int>
#define LL long long
using namespace std;
const int MAXN = 100005;
const LL MOD = 998244353;
const LL INF = (LL)1e9 + 5;

struct ST {
	int N, maxv[9*MAXN];
	void init(vector<int> &tour, int l, int r, int idx) {
		if (l == r) {
			maxv[idx] = tour[l];
			return;
		}
		int m = (l + r) >> 1;
		init(tour, l, m, idx << 1);
		init(tour, m + 1, r, idx << 1 | 1);
		maxv[idx] = min(maxv[idx << 1], maxv[idx << 1 | 1]);
	}
	int RMQ(int ql, int qr, int l, int r, int idx) {
		assert(max(ql, l) <= min(qr, r));
//		if (idx < 10) cout << "RMQ! " << ql << " " << qr << " " << l << " " << r << '\n';
		if (ql <= l && r <= qr) {
			return maxv[idx];
		}
		
		int m = (l + r) >> 1;
		if (qr <= m) {
			return RMQ(ql, qr, l, m, idx << 1);
		}
		if (ql > m) {
			return RMQ(ql, qr, m + 1, r, idx << 1 | 1);
		}
		
		int q1 = RMQ(ql, qr, l, m, idx << 1);
		int q2 = RMQ(ql, qr, m + 1, r, idx << 1 | 1);
		return min(q1, q2);
	}
} tree;

int N, Q, M, st[MAXN], col[MAXN], dep[MAXN], ans[MAXN];
vector<int> tour, G[MAXN];
set<int> grp[MAXN];

void dfs(int v, int p, int d) {
	dep[v] = d;
	st[v] = tour.size();
	tour.push_back(dep[v]);
	for (int to : G[v]) {
		if (to == p) continue;
		dfs(to, v, d + 1);
		tour.push_back(dep[v]);
	}
}

void put_in(int v, int c) {
//	cout << "Put " << v << " into " << c << " " << ans[c] << '\n';
	ans[c] += dep[v];
	auto it = grp[c].lower_bound(st[v]);
	
	if (it != grp[c].end()) {
		assert(*it != st[v]);
		ans[c] -= tree.RMQ(st[v], *it, 1, M, 1);
	}
	if (it != grp[c].begin()) {
		auto pre = prev(it);
		ans[c] -= tree.RMQ(*pre, st[v], 1, M, 1);
	}
	if (it != grp[c].begin() && it != grp[c].end()) {
		auto pre = prev(it);
		ans[c] += tree.RMQ(*pre, *it, 1, M, 1);
	}
	grp[c].insert(st[v]);
}

void take_out(int v, int c) {
//	cout << "Take " << v << " out of " << c << ' ' << ans[c] << '\n';
	ans[c] -= dep[v];
	auto it = grp[c].lower_bound(st[v]);
	assert(*it == st[v]);
	if (next(it) != grp[c].end()) {
		auto nxt = next(it);
		ans[c] += tree.RMQ(st[v], *nxt, 1, M, 1);
//		cout << "Q to " << st[v] << " " << *it << '\n';
//		cout << "Add " << tree.RMQ(st[v], *it, 1, M, 1) << '\n';
	}
	if (it != grp[c].begin()) {
		auto pre = prev(it);
		ans[c] += tree.RMQ(*pre, st[v], 1, M, 1);
	}
	if (it != grp[c].begin() && next(it) != grp[c].end()) {
		auto pre = prev(it);
		auto nxt = next(it);
		ans[c] -= tree.RMQ(*pre, *nxt, 1, M, 1);
	}
	grp[c].erase(it);
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);

	cin >> N;
	for (int i = 0; i < N - 1; i++) {
		int a, b;
		cin >> a >> b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	
	tour.push_back(INF);
	dfs(1, 1, 0);
	M = tour.size() - 1;
	tree.init(tour, 1, M, 1);
//	cout << "HERE!!\n";
	
	for (int i = 1; i <= N; i++) {
		cin >> col[i];
		put_in(i, col[i]);
	}
	
	cin >> Q;
	while (Q--) {
		char tp;
		int x, y;
		cin >> tp >> x;
		if (tp == 'Q') {
			if (grp[x].empty()) {
				cout << "-1\n";
			}
			else {
				int lca = tree.RMQ(*grp[x].begin(), *prev(grp[x].end()), 1, M, 1);
//				cout << "Get lca " << lca << '\n';
				cout << ans[x] - lca << '\n';
			}
		}
		else {
			cin >> y;
			if (y == col[x]) continue;
			take_out(x, col[x]);
			col[x] = y;
			put_in(x, col[x]);
		}
	}

	return 0;
}
