#include <bits/stdc++.h>
using namespace std;
#define ri register int
typedef long long ll;
#define rll register ll
namespace io {
	const int SIZE = (1 << 21) + 1;
	char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c, qu[55]; int f, qr;
	// getchar
	#define gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	// print the remaining part
	inline void flush () {
		fwrite (obuf, 1, oS - obuf, stdout);
		oS = obuf;
	}
	// putchar
	inline void putc (char x) {
		*oS ++ = x;
		if (oS == oT) flush ();
	}
	// input a signed integer
	template <class I>
	inline void gi (I &x) {
		for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
		for (x = 0; c <= '9' && c >= '0'; c = gc()) x = (x << 1) + (x << 3) + (c & 15); x *= f;
	}
	// input a letter
	template <class I>
	inline void get (I &x) {
		for (c = gc(); c < 'A' || c > 'Z'; c = gc()) ;
		x = c;
	}
	// print a signed integer
	template <class I>
	inline void print (I x) {
		if (!x) putc ('0'); if (x < 0) putc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0',  x /= 10;
		while (qr) putc (qu[qr --]);
	}
	//no need to call flush at the end manually!
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
}
using io :: gi;
using io :: get;
using io :: putc;
using io :: print;
const int N=85,M=105,inf=2e9,L=325;
const ll INF=1e8;
int flag,x0[N],_y0[N],lx[M],rx[M],ly[M],ry[M];
ll v0[N];
struct node{
	char op;
	int a,b;
}q[L];
inline void chmin(int &x,ri y){
	x=min(x,y);
}
inline void chmax(int &x,ri y){
	x=max(x,y);
}
namespace G{
	const int _N=(M<<1)+N,_M=(M<<1)+(N<<1); 
	const ll INF=1e18;
	int size,s,t,m,a[_M],b[_M],c[_M],d[_M],deg[_N],
	tot,head[_N],nxt[_M<<2],adj[_M<<2],cap[_M<<2],q[_M<<5],S,T,flow,sum,vis[_N],cur[_N];
	ll cost,dis[_N],val[_M<<2],e[_M];
	inline void addedge(ri x,ri y,ri c,rll w){
		nxt[++tot]=head[x];
		adj[head[x]=tot]=y;
		cap[tot]=c;
		val[tot]=w;
	}
	inline void Add(ri x,ri y,ri c,rll v){
		addedge(x,y,c,v);
		addedge(y,x,0,-v);
	}
	inline void add(ri x,ri y,ri lower,ri upper,rll cost){
		if(lower>upper) flag=0;
		++m;
		a[m]=x;
		b[m]=y;
		c[m]=lower;
		d[m]=upper;
		e[m]=cost;
	}
	inline void build(){
		ri i;
		cost=0;
		for(i=1;i<=m;++i)
			deg[a[i]]-=c[i],
			deg[b[i]]+=c[i],
			cost+=c[i]*e[i],
			Add(a[i],b[i],d[i]-c[i],e[i]);
		S=size+1;
		T=size+2;
		sum=0;
		for(i=1;i<=size;++i){
			if(deg[i]>0) Add(S,i, deg[i],0),sum+=deg[i];
			if(deg[i]<0) Add(i,T,-deg[i],0);
		}
		Add(t,s,inf,0);
		size+=2;
	}
	inline bool spfa(){
		ri l,r,x,y,i;
		for(i=1;i<=size;++i) dis[i]=-INF,vis[i]=0,cur[i]=head[i];
		q[l=r=1]=S;dis[S]=0; 
		while(l<=r){
			x=q[l++];vis[x]=0; 
			for(i=head[x];i;i=nxt[i])
				if(cap[i]&&dis[y=adj[i]]<dis[x]+val[i]){
					dis[y]=dis[x]+val[i];
					if(!vis[y]) q[++r]=y,vis[y]=1;
				}
		}
		return dis[T]>-INF;
	}
	inline int dfs(ri x,ri now){
		if(x==T) return now;
		vis[x]=1;
		ri y,tmp,res=0;
		for(int &i=cur[x];i;i=nxt[i])
			if(!vis[y=adj[i]]&&cap[i]&&dis[y]==dis[x]+val[i])
				if(cap[i]-=(tmp=dfs(y,min(now-res,cap[i]))),cap[i^1]+=tmp,(res+=tmp)==now)
					return vis[x]=false,res;
		return res;
	}
	inline ll costflow(){
		ri tmp;
		flow=0;
		while(spfa())
			tmp=dfs(S,inf),
			flow+=tmp,
			cost+=tmp*dis[T];
		if(flow!=sum) return -INF;
		return cost;
	}
	inline void clear(){
		tot=1;m=0;
		for(ri i=1;i<=size;++i) head[i]=deg[i]=0;
	}
}
int posx[M],posy[M];
int main(){
	ri n,m,i,k,limx,limy;
	gi(n);
	limx=limy=0;
	for(i=1;i<=n;++i)
		gi(x0[i]),gi(_y0[i]),gi(v0[i]),
		limx=max(limx,x0[i]),
		limy=max(limy,_y0[i]);
	gi(m);
	for(i=1;i<=m;++i){
		get(q[i].op);gi(q[i].a);gi(q[i].b);
		if(q[i].op=='L'||q[i].op=='R')
			limx=max(limx,q[i].a);
		else
			limy=max(limy,q[i].a);
	}
	rll ans=0; 
	for(k=1;k<=n;++k){
		G::clear();
		for(i=1;i<=limx;++i)
			lx[i]=0,
			rx[i]=inf;
		for(i=1;i<=limy;++i)
			ly[i]=0,
			ry[i]=inf;
		flag=1;
		for(i=1;i<=m;++i)
			if(q[i].op=='L')
				chmin(rx[q[i].a],q[i].b);
			else if(q[i].op=='R'){
				if(q[i].a-1==0){
					if(k-q[i].b>0){
						flag=0;
						break;
					}
				}
				else
					chmax(lx[q[i].a-1],k-q[i].b);
			}
			else if(q[i].op=='D')
				chmin(ry[q[i].a],q[i].b);
			else{
				if(q[i].a-1==0){
					if(k-q[i].b>0){
						flag=0;
						break;
					}
				}
				else
					chmax(ly[q[i].a-1],k-q[i].b);
			}
		if(!flag) continue;
		for(i=1;i<=limx;++i)
			lx[i]=max(lx[i-1],lx[i]);
		for(i=limx-1;i;--i)
			rx[i]=min(rx[i+1],rx[i]);
		for(i=1;i<=limy;++i)
			ly[i]=max(ly[i-1],ly[i]);
		for(i=limy-1;i;--i)
			ry[i]=min(ry[i+1],ry[i]);
		G::size=n;
		for(i=1;i<=limx;++i)
			posx[i]=++G::size;
		for(i=1;i<=limy;++i)
			posy[i]=++G::size;
		G::s=++G::size;
		G::t=++G::size;
		G::add(G::s,posx[limx],max(k,lx[limx]),min(k,rx[limx]),0);
		for(i=limx-1;i;--i)
			G::add(posx[i+1],posx[i],lx[i],rx[i],0);
		G::add(posy[limy],G::t,ly[limy],ry[limy],0);
		for(i=1;i<limy;++i)
			G::add(posy[i],posy[i+1],ly[i],ry[i],0);
		for(i=1;i<=n;++i)
			G::add(posx[x0[i]],i,0,1,v0[i]),
			G::add(i,posy[_y0[i]],0,1,0);
		if(!flag) continue;
		G::build();
		ans=max(ans,G::costflow());
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 2304