#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
long double ABS(long double a){return max(a,-a);}

namespace MCF {
	// required <string.h> <vector> <queue> <algorithm>
	#define MAXN 350
	#define MAXM 200000
	#define wint int
	#define cint long long
	const wint wEPS = 0;
	const wint wINF = 1001001001;
	const cint cEPS = 0;
	const cint cINF = inf;
	int n, m, ptr[MAXN], next[MAXM], zu[MAXM];
	wint capa[MAXM], tof;
	cint cost[MAXM], toc, d[MAXN], pot[MAXN];
	int vis[MAXN], pree[MAXN];
	void init(int _n) {
		n = _n; m = 0; memset(ptr, ~0, n * 4);
	}
	void ae(int u, int v, wint w, cint c) {
		next[m] = ptr[u]; ptr[u] = m; zu[m] = v; capa[m] = w; cost[m] = +c; ++m;
		next[m] = ptr[v]; ptr[v] = m; zu[m] = u; capa[m] = 0; cost[m] = -c; ++m;
	}
	bool solve(int src, int ink, wint flo = wINF) {
		int i, u, v;
		wint f;
		cint c, cc;
		memset(pot, 0, n * sizeof(cint));
		//*
		for (bool cont = 1; cont; ) {
			cont = 0;
			for (u = 0; u < n; ++u) for (i = ptr[u]; ~i; i = next[i]) if (capa[i] > wEPS) {
				if (pot[zu[i]] > pot[u] + cost[i] + cEPS) {
					pot[zu[i]] = pot[u] + cost[i]; cont = 1;
				}
			}
		}
		//*/
		for (toc = 0, tof = 0; tof + wEPS < flo; ) {
			typedef pair<cint,int> node;
			priority_queue< node,vector<node>,greater<node> > q;
			for (u = 0; u < n; ++u) { d[u] = cINF; vis[u] = 0; }
			for (q.push(make_pair(d[src] = 0, src)); !q.empty(); ) {
				c = q.top().first; u = q.top().second; q.pop();
				if (vis[u]++) continue;
				for (i = ptr[u]; ~i; i = next[i]) if (capa[i] > wEPS) {
					cc = c + cost[i] + pot[u] - pot[v = zu[i]];
					if (d[v] > cc + cEPS) { q.push(make_pair(d[v] = cc, v)); pree[v] = i; }
				}
			}
			if (!vis[ink]) return 0;
			f = flo - tof;
			for (v = ink; v != src; v = zu[i ^ 1]) { i = pree[v]; f=min(f,capa[i]); }
			for (v = ink; v != src; v = zu[i ^ 1]) { i = pree[v]; capa[i] -= f; capa[i ^ 1] += f; }
			tof += f;
			toc += f * (d[ink] - pot[src] + pot[ink]);
			for (u = 0; u < n; ++u) pot[u] += d[u];
		}
		return 1;
	}
}
int X[100];
int Y[100];
long long C[100];
char t[400];
int p[400];
int q[400];
int L[400];
int R[400];
int main(){
	int a;scanf("%d",&a);
	for(int i=0;i<a;i++){
		scanf("%d%d%lld",X+i,Y+i,C+i);
	}
	int b;scanf("%d",&b);
	for(int i=0;i<b;i++){
		scanf("%s%d%d",t+i,p+i,q+i);
	}
	long long ret=0;
	for(int i=1;i<=a;i++){
		MCF::init(350);
		for(int j=0;j<a;j++){
			MCF::ae(j*2,j*2+1,1,1000000000000000LL-C[j]);
		}
		int S=348;
		int T=349;
		for(int j=0;j<i;j++){
			L[j]=0;
			R[j]=100;
		}
		for(int j=0;j<b;j++){
			if(t[j]!='L'&&t[j]!='R')continue;
			if(q[j]>=i)continue;
			if(t[j]=='L'){
				L[q[j]]=max(L[q[j]],p[j]+1);
			}else{
				R[i-1-q[j]]=min(R[i-1-q[j]],p[j]-1);
			}
		}
		for(int j=1;j<i;j++){
			L[j]=max(L[j],L[j-1]);
		}
		for(int j=i-2;j>=0;j--){
			R[j]=min(R[j],R[j+1]);
		}
		for(int j=0;j<i;j++){
			MCF::ae(S,a*2+j,1,0);
			for(int k=0;k<a;k++){
				if(L[j]<=X[k]&&X[k]<=R[j])MCF::ae(a*2+j,k*2,1,0);
			}
		}
		for(int j=0;j<i;j++){
			L[j]=0;
			R[j]=100;
		}
		for(int j=0;j<b;j++){
			if(t[j]!='D'&&t[j]!='U')continue;
			if(q[j]>=i)continue;
			if(t[j]=='D'){
				L[q[j]]=max(L[q[j]],p[j]+1);
			}else{
				R[i-1-q[j]]=min(R[i-1-q[j]],p[j]-1);
			}
		}
		for(int j=1;j<i;j++){
			L[j]=max(L[j],L[j-1]);
		}
		for(int j=i-2;j>=0;j--){
			R[j]=min(R[j],R[j+1]);
		}
		for(int j=0;j<i;j++){
			MCF::ae(a*3+j,T,1,0);
			for(int k=0;k<a;k++){
				if(L[j]<=Y[k]&&Y[k]<=R[j])MCF::ae(k*2+1,a*3+j,1,0);
			}
		}
		bool res=MCF::solve(S,T,i);
		if(!res)continue;
		ret=max(ret,1000000000000000LL*i-MCF::toc);
	}
	printf("%lld\n",ret);
}

Measured memory_bytes: 640