#include<bits/stdc++.h>
using namespace std;
#define gc getchar()
#define pc putchar
#define li long long
inline li read(){
	li x = 0,y = 0,c = gc;
	while(!isdigit(c)) y = c,c = gc;
	while(isdigit(c)) x = (x << 1) + (x << 3) + (c ^ '0'),c = gc;
	return y == '-' ? -x : x;
}
inline void print(li q){
	if(q < 0) pc('-'),q = -q;
	if(q >= 10) print(q / 10);
	pc(q % 10 + '0');
}
#define ldb long double
ldb p[510][510],q[510][510];
int n,m,cnt;
li x[510],y[510],a[510];
inline bool chk(){
	for(int i = 0;i <= n + m;++i) for(int j = 0;j <= cnt;++j){
		ldb tp = abs(p[i][j]) - (li)(abs(p[i][j]) + 0.5l);
		//cerr<<i<<" "<<j<<" "<<p[i][j]<<" "<<tp<<" "<<(li)(p[i][j] + 0.5l)<<endl;
		if(abs(tp) > 1e-8l) return 0;
	}
	return 1;
}
int ji[510];
li calc(){
	int i,j;
	memset(ji,0,sizeof(ji));
	for(i = n + 1;i <= cnt;++i) ji[i] = i - n;
	ji[n] = n + m + 1;
	for(i = 0;i <= n + m;++i){
		li tp = q[i][n];
		for(j = 0;j <= cnt;++j) q[i][j] -= q[n + m + 1][j] * tp;
	}
	//for(i = 0;i <= n + m + 1;++i){
	//	for(j = 0;j <= cnt;++j) cout<<q[i][j]<<" ";cout<<endl;
	//}
	//cout<<endl;
	//for(i = 1;i <= cnt;++i) cout<<ji[i]<<" ";
	//cout<<endl<<endl<<endl;
	//for(i = 1;i <= n + m + 1;++i) cerr<<q[i][0]<<" ";cerr<<endl;
	//for(i = 1;i <= n + m + 1;++i) if(q[i][0] < 0) return 0;
	//for(i = 1;i <= n;++i) cerr<<ji[i]<<" ";cerr<<endl;
	while(1){
		int fg = 0;
		for(i = 1;i <= cnt;++i) if(ji[i]) if(q[ji[i]][0] < 0 && (!fg || q[ji[i]][0] < q[ji[fg]][0])) fg = i;
		if(!fg) break;
		int tp = 0,tmp = 0;
		for(i = 1;i <= cnt;++i) if(q[ji[fg]][i] < 0 && (!tp || q[ji[fg]][i] < q[ji[fg]][tp])) tp = i;
		//for(i = 1;i <= n + m + 2;++i) if(q[i][fg] > 0 && (!tp || q[i][0] / q[i][fg] < q[tp][0] / q[tp][fg])) tp = i;
		//cerr<<fg<<"*"<<tp<<endl;
		if(!tp) return 0;
		ji[tp] = ji[fg];tmp = fg;fg = ji[fg];ji[tmp] = 0;swap(tp,fg);
		//tmp = tp;tp = ji[tmp];ji[tmp] = 0;ji[fg] = tp;
		for(i = 0;i <= cnt;++i) if(i != fg) q[tp][i] /= q[tp][fg];q[tp][fg] = 1;
		for(i = 0;i <= n + m + 1;++i) if(i != tp){
			for(j = 0;j <= cnt;++j) if(j != fg) q[i][j] -= q[i][fg] * q[tp][j];q[i][fg] = 0;
		} 
		//cout<<fg<<"*"<<tp<<" "<<(li)(-q[0][0] + 0.5l)<<endl;
		//cerr<<fg<<"*"<<tp<<endl;
		//for(i = 0;i <= n + m;++i){
		//	if(i == 12) cerr<<"*";
		//	for(j = 0;j <= cnt;++j) cout<<q[i][j]<<" ";cout<<endl;
		//}
		//cerr<<endl;
		//for(i = 1;i <= cnt;++i) cerr<<ji[i]<<" ";
		//cout<<endl<<endl<<endl;
		//if(chk()) as = max(as,(li)(-q[0][0] + 0.5l));
		//system("pause");
	}
	//int ctt = 0;
	//for(i = 1;i <= n;++i) cerr<<ji[i]<<" ";cerr<<endl;
	//for(i = 1;i <= n;++i) if(ji[i] && q[ji[i]][0] > 1 - 1e-8l) ++ctt;
	//cerr<<ctt<<endl;
	while(1){
		int fg = 0;
		for(i = 1;i <= cnt;++i) if(!ji[i]) if(q[0][i] > 0 && (!fg || q[0][i] > q[0][fg])) fg = i;
		if(!fg) break;
		int tp = 0,tmp = 0;
		for(i = 1;i <= cnt;++i) if(ji[i]) if(q[ji[i]][fg] > 0 && (!tp || q[ji[i]][0] / q[ji[i]][fg] < q[ji[tp]][0] / q[ji[tp]][fg])) tp = i;
		//for(i = 1;i <= n + m + 2;++i) if(q[i][fg] > 0 && (!tp || q[i][0] / q[i][fg] < q[tp][0] / q[tp][fg])) tp = i;
		if(!tp) return 0;
		tmp = tp;tp = ji[tmp];ji[tmp] = 0;ji[fg] = tp;
		for(i = 0;i <= cnt;++i) if(i != fg) q[tp][i] /= q[tp][fg];q[tp][fg] = 1;
		for(i = 0;i <= n + m + 1;++i) if(i != tp){
			for(j = 0;j <= cnt;++j) if(j != fg) q[i][j] -= q[i][fg] * q[tp][j];q[i][fg] = 0;
		} 
		//cout<<fg<<"*"<<tp<<" "<<(li)(-q[0][0] + 0.5l)<<endl;
		//cerr<<fg<<"*"<<tp<<endl;
		//for(i = 0;i <= n + m;++i){
		//	if(i == 12) cerr<<"*";
		//	for(j = 0;j <= cnt;++j) cout<<q[i][j]<<" ";cout<<endl;
		//}
		//cerr<<endl;
		//for(i = 1;i <= cnt;++i) cerr<<ji[i]<<" ";
		//cout<<endl<<endl<<endl;
		//if(chk()) as = max(as,(li)(-q[0][0] + 0.5l));
		//system("pause");
	}
	li as = 0;
	//for(i = 1;i <= cnt;++i) if(ji[i]) if(q[ji[i]][0] < 0) return 0;
	//for(i = 1;i <= n;++i) cerr<<(ji[i] ? q[ji[i]][0] : 0)<<" ";cerr<<endl;
	for(i = 1;i <= n;++i) if(ji[i]){
		if(q[ji[i]][0] > 1 - 1e-8l) as += a[i];
	} 
	//cerr<<as<<endl;
	return as;
	//return (li)(-q[0][0] + 0.5l);
}
int main(){
	//system("mode con cols=200 lines=1000");
	int i,j,k,l,u,v;
	n = read();for(i = 1;i <= n;++i) x[i] = read(),y[i] = read(),a[i] = read();cnt = n;
	m = read();
	char c;
	for(i = 1;i <= m;++i){
		c = gc;while(c < 'A' || c > 'Z') c = gc;
		u = read();v = read();
		p[i][0] = v;
		if(c == 'U'){
			for(j = 1;j <= n;++j) if(y[j] >= u) p[i][j] = 1;
		} 
		else if(c == 'D'){
			for(j = 1;j <= n;++j) if(y[j] <= u) p[i][j] = 1;
		} 
		else if(c == 'L'){
			for(j = 1;j <= n;++j) if(x[j] <= u) p[i][j] = 1;
		} 
		else{
			for(j = 1;j <= n;++j) if(x[j] >= u) p[i][j] = 1;
		} 
		p[i][++cnt] = 1;
		//ji[cnt] = i;
	}
	for(i = 1;i <= n;++i){
		p[i + m][i] = p[i + m][++cnt] = p[i + m][0] = 1;
		//ji[cnt] = i + m;
	} 
	//cerr<<n + m<<" "<<cnt<<endl;
	for(i = 1;i <= n;++i) p[0][i] = a[i];
	//freopen("out.txt","w",stdout);
	//for(i = 0;i <= n + m + 1;++i){
	//	for(j = 0;j <= cnt;++j) cout<<p[i][j]<<" ";cout<<endl;
	//}
	//cerr<<endl;
	//for(i = 1;i <= cnt;++i) cerr<<ji[i]<<" ";
	//cout<<endl<<endl<<endl;
	li as = 0;
	for(i = 1;i <= n;++i) p[n + m + 1][i] = 1,p[n + m + 2][i] = -1;
	//freopen("qwq.out","w",stdout);
	for(int qwq = 1;qwq <= n;++qwq){
		//cerr<<qwq<<":"<<endl;
		for(i = 0;i <= n + m + 1;++i) for(j = 0;j <= cnt;++j) q[i][j] = p[i][j];
		q[n + m + 1][0] = qwq;//q[n + m + 2][0] = -qwq;
		as = max(as,calc());
	}
	//for(i = 1;i <= cnt;++i) cerr<<(ji[i] ? p[ji[i]][0] : 0)<<" ";cerr<<endl;
	print(as);
	//print(as);
	return 0;
}

Measured memory_bytes: 6400