#include <stdio.h>
#include <assert.h>
#include <setjmp.h>
#include <string.h>
#define V 204
#define MAXE 23333
#define S 202
#define T 203
#define Min(x, y) ((x)<(y)?(x):(y))
#define Max(x, y) ((x)>(y)?(x):(y))
#define CMin(x, y) ((y)<x?(x=(y), 1):0)
#define CMax(x, y) (x<(y)?(x=(y), 1):0)
#define meow(args...) fprintf(stderr, args)
int e, x[80], y[80], lim[4][102], head[V], next[MAXE], to[MAXE], cap[MAXE], from[V], diff[V];
long long v[80], cost[MAXE], dis[V], maxcost;
jmp_buf env;
void adde(int u, int v, int w, long long c)
{
	next[e]=head[u], to[e]=v, cap[e]=w, cost[e]= c, head[u]=e++;
	next[e]=head[v], to[e]=u, cap[e]=0, cost[e]=-c, head[v]=e++;
}
void add_edge(int u, int v, int max, int min, long long c)
{
	CMax(min, 0);
	if(min>max) longjmp(env, 1);
	if(min<max) adde(u, v, max-min, c);
	diff[u]+=min;
	diff[v]-=min;
	maxcost+=min*c;
}
int ford()
{
	static int inq[V], queue[65536];
	unsigned short qhead=0, qtail=0;
	memset(dis, 192, V*sizeof(long long));
	dis[S]=0;
	inq[queue[qtail++]=S]=1;
	while(qhead!=qtail) {
		int x=queue[qhead++], i;
		inq[x]=0;
		for(i=head[x]; ~i; i=next[i])
			if(cap[i] && CMax(dis[to[i]], dis[x]+cost[i])) {
				from[to[i]]=i;
				if(!inq[to[i]]) inq[queue[qtail++]=to[i]]=1;
			}
	}
	return dis[T]>=-1e18;
}
int main()
{
	int n, m, i, j;
	long long ans=0;
	scanf("%d", &n);
	for(i=0; i<n; ++i) scanf("%d%d%lld", &x[i], &y[i], &v[i]);
	scanf("%d", &m);
	for(i=0; i<4; ++i) for(j=1; j<=100; ++j) lim[i][j]=n;
	for(i=0; i<m; ++i) {
		char d[2];
		int a, b;
		scanf("%s%d%d", d, &a, &b);
		lim[(d[0]=='R')+2*(d[0]=='U')+3*(d[0]=='D')][a]=b;
	}
	if(!setjmp(env)) {
		for(j=1; j<=lim[1][1] && j<=lim[3][100]; ++j) {
			maxcost=0;
			memset(head, -1, V*sizeof(int));
			memset(diff, 0, V*sizeof(int));
			e=0;
			for(i=1; i<=100; ++i) {
				add_edge(i-1, i, lim[2][i], j-lim[3][i-1], 0);
				add_edge(i+100, i+101, lim[0][i], j-lim[1][i+1], 0);
			}
			for(i=0; i<n; ++i) adde(y[i], x[i]+100, 1, v[i]);
			add_edge(201, 0, j, j, 0);
			for(i=0; i<202; ++i) {
				if(diff[i]>0) adde(i, T,  diff[i], 0);
				if(diff[i]<0) adde(S, i, -diff[i], 0);
			}
			while(ford()) {
				int flow=1e9;
				for(i=T; i!=S; i=to[from[i]^1]) CMin(flow, cap[from[i]]);
				maxcost+=flow*dis[T];
				for(i=T; i!=S; i=to[from[i]^1]) {
					cap[from[i]]-=flow;
					cap[from[i]^1]+=flow;
				}
			}
			for(i=head[S]; ~i; i=next[i]) if(cap[i]) longjmp(env, 1);
			CMax(ans, maxcost);
		}
	}
	printf("%lld\n", ans);
	return 0;
}
