#include <cmath>
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <utility>
using namespace std;
typedef long long LL;
typedef pair<int, LL> PII;
const int N = 100005, BIG = 0, SMALL = 1;
vector<int> big;
vector<PII> F[N];
LL sum[N][2], gsum[3];
int deg[N], n, m, type[N], col[N];

struct Edge{
	int from, to;
	LL w;
	Edge(int ff, int tt, LL ww){
		from = ff; to = tt; w = ww;
	}
	bool operator<(const Edge &a) const{
		if(from != a.from) return from < a.from;
		return to < a.to;
	}
	bool operator==(const Edge &a) const{
		return (from == a.from && to == a.to);
	}
};
vector<Edge> tE, E;

void addE(const Edge &e){
	E.push_back(e);
	deg[e.from]++;
	deg[e.to]++;
}

void getE(){
	sort(tE.begin(), tE.end());
	addE(tE[0]);
	for(int i = 1; i < tE.size(); i++){
		if(tE[i] == tE[i - 1]){
			E.back().w += tE[i].w;
		}
		else{
			addE(tE[i]);
		}
	}
}

inline int id(int c1, int c2){
	return (c1 == c2 ? c1 : 2);
}

void init(){
	int lim = (int)sqrt(2 * m);
	for(int i = 1; i <= n; i++){
		if(deg[i] > lim){
			type[i] = BIG;
			big.push_back(i);
		}
		else{
			type[i] = SMALL;
		}
	}
	for(int i = 0; i < E.size(); i++){
		Edge &e = E[i];
		int a = e.from, b = e.to;
		if(type[a] == BIG){
			sum[a][col[b]] += e.w;
			F[b].push_back(PII(a, e.w));
		}
		else if(type[b] == BIG){
			sum[b][col[a]] += e.w;
			F[a].push_back(PII(b, e.w));
		}
		else{
			int t = id(col[a], col[b]);
			gsum[t] += e.w;
			F[a].push_back(PII(b, e.w));
			F[b].push_back(PII(a, e.w));
		}
	}
}

void change(int a){
	if(type[a] == BIG){
		for(int i = 0; i < F[a].size(); i++){
			int b = F[a][i].first;
			LL w = F[a][i].second;
			sum[b][col[a]] -= w;
			sum[b][col[a] ^ 1] += w;
		}
	}
	else{
		for(int i = 0; i < F[a].size(); i++){
			int b = F[a][i].first;
			LL w = F[a][i].second;
			if(type[b] == BIG){
				sum[b][col[a]] -= w;
				sum[b][col[a] ^ 1] += w;
			}
			else{
				int t = id(col[a], col[b]);
				gsum[t] -= w;
				t = id(col[a] ^ 1, col[b]);
				gsum[t] += w;
			}
		}
	}
	col[a] ^= 1;
}

LL query(int c1, int c2){
	LL ret = gsum[id(c1, c2)];
	for(int i = 0; i < big.size(); i++){
		int a = big[i];
		if(col[a] == c1) ret += sum[a][c2];
		else if(col[a] == c2) ret += sum[a][c1];
	}
	return ret;
}

void clear(){
	big.clear();
	tE.clear();
	E.clear();
	for(int i = 1; i <= n; i++) F[i].clear();
	memset(sum, 0, sizeof(sum));
	memset(gsum, 0, sizeof(gsum));
	memset(deg, 0, sizeof(deg));
}

int main(){
	int cs = 0;
	while(2 == scanf("%d %d", &n, &m)){
		printf("Case %d:\n", ++cs);
		clear();
		for(int i = 1; i <= n; i++) scanf("%d", col + i);
		for(int i = 0; i < m; i++){
			int a, b, w;
			scanf("%d %d %d", &a, &b, &w);
			if(a > b) swap(a, b);
			tE.push_back(Edge(a, b, w));
		}
		getE();
		init();
		int q;
		scanf("%d", &q);
		while(q--){
			static char cmd[20];
			scanf("%s", cmd);
			if(cmd[0] == 'A'){
				int a, b;
				scanf("%d %d", &a, &b);
				printf("%lld\n", query(a, b));
			}
			else{
				int a;
				scanf("%d", &a);
				change(a);
			}
		}
	}
	return 0;
}
