#include<bits/stdc++.h>
using namespace std;
#define mpr make_pair
typedef long long LL;
typedef pair < int , int > pii;
typedef pair < LL , int > pli;
const LL INF=(LL)(1e15+5),LINF=(LL)(2e18+5);
int n,m,x[80],y[80],px[80],py[80];
LL v[80];
char readch(){
	char c=getchar();
	while(c!='L' && c!='R' && c!='U' && c!='D'){
		c=getchar();
	}
	return c;
}
namespace flows{
	struct edge{
		int v,f,r;
		LL c;
		void set(int V,int F,int R,LL C){
			v=V;f=F;r=R;c=C;
		}
	}tmp;
	vector < edge > adj[505];
	priority_queue < pli > pq;
	int predv[505],prede[505],flow;
	LL f[505],dis[505],cost;
	void init(){
		int i;
		for(i=0;i<505;++i) adj[i].clear();
		memset(f,0,sizeof(f));
		flow=0;cost=0ll;
	}
	void addedge(int u,int v,int f,LL c){
		tmp.set(v,f,(int)adj[v].size(),c);
		adj[u].push_back(tmp);
		tmp.set(u,0,(int)adj[u].size()-1,-c);
		adj[v].push_back(tmp);
	}
	void dijkstra(){
		int i,j,k;
		fill(dis,dis+505,LINF);
		dis[0]=0ll;
		pq.push(mpr(0ll,0));
		while(!pq.empty()){
			LL D=-pq.top().first;
			int cur=pq.top().second;
			pq.pop();
			if(dis[cur]!=D) continue;
			for(i=0;i<(int)adj[cur].size();++i){
				if(!adj[cur][i].f) continue;
				int v=adj[cur][i].v;
				LL l=adj[cur][i].c+f[cur]-f[v];
				if(D+l<dis[v]){
					dis[v]=D+l;
					predv[v]=cur;
					prede[v]=i;
					pq.push(mpr(-dis[v],v));
				}
			}
		}
		memcpy(f,dis,sizeof(f));
	}
	void mincostflow(){
		int i,j,k;
		while(1){
			dijkstra();
			if(dis[3]==LINF) return;
			LL c=0ll;
			int f=10000;
			for(i=3;i;i=predv[i]){
				edge &E=adj[predv[i]][prede[i]];
				f=min(f,E.f);
				c+=E.c;
			}
			flow+=f;
			cost+=c*(LL)f;
			for(i=3;i;i=predv[i]){
				edge &E=adj[predv[i]][prede[i]];
				E.f-=f;
				adj[i][E.r].f+=f;
			}
		}
	}
};
bool cmpx(int a,int b){
	return x[a]<x[b];
}
bool cmpy(int a,int b){
	return y[a]<y[b];
}
char TP[405];
int D[405],V[405];
vector < pii > consx,consy;
LL solve(int tot){
	int i,j,k;
	consx.clear();
	consy.clear();
	for(i=0;i<m;++i){
		if(TP[i]=='L')
			consx.push_back(mpr(D[i],V[i]));
		else if(TP[i]=='R' && V[i]<tot)
			consx.push_back(mpr(D[i]-1,-tot+V[i]));
		else if(TP[i]=='D')
			consy.push_back(mpr(D[i],V[i]));
		else if(TP[i]=='U' && V[i]<tot)
			consy.push_back(mpr(D[i]-1,-tot+V[i]));
	}
	sort(consx.begin(),consx.end());
	sort(consy.begin(),consy.end());
	flows::init();
	// 0: super source  1: original source  2: extra source
	// 3: super sink  4: original sink  5: extra sink
	flows::addedge(0,1,tot,0);
	flows::addedge(4,3,tot,0);
	int extraflow=0,ptr=n-1,pr=1,SX=(int)consx.size();
	for(i=SX-1;i>=0;--i){
		int d=consx[i].first,f=consx[i].second;
		if(i==SX-1 || consx[i+1].first!=d){
			while(ptr>=0 && x[px[ptr]]>d){
				flows::addedge(pr,6+SX+px[ptr],1,0);
				--ptr;
			}
		}
		if(f<0){
			f=-f;
			extraflow+=f;
			flows::addedge(2,i+6,f,0);
			flows::addedge(pr,5,f,0);
			flows::addedge(pr,i+6,tot-f,0);
		}
		else flows::addedge(pr,i+6,f,0);
		pr=i+6;
	}
	while(ptr>=0){
		flows::addedge(pr,6+SX+px[ptr],1,0);
		--ptr;
	}
	for(i=0;i<n;++i){
		flows::addedge(6+SX+i,6+SX+n+i,1,INF-v[i]);
	}
	ptr=0;pr=-1;
	int pf;
	for(i=0;i<(int)consy.size();++i){
		int d=consy[i].first,cur=6+SX+n*2+i;
		while(ptr<n && y[py[ptr]]<=d){
			flows::addedge(6+SX+n+py[ptr],cur,1,0);
			++ptr;
		}
		if(pr!=-1){
			if(pf<0){
				pf=-pf;
				extraflow+=pf;
				flows::addedge(2,cur,pf,0);
				flows::addedge(pr,5,pf,0);
				flows::addedge(pr,cur,tot-pf,0);
			}
			else flows::addedge(pr,cur,pf,0);
		}
		pf=consy[i].second;
		pr=cur;
	}
	if(pr!=-1){
		if(pf<0){
			pf=-pf;
			extraflow+=pf;
			flows::addedge(2,4,pf,0);
			flows::addedge(pr,5,pf,0);
			flows::addedge(pr,4,tot-pf,0);
		}
		else flows::addedge(pr,4,pf,0);
	}
	while(ptr<n){
		flows::addedge(6+SX+n+py[ptr],4,1,0);
		++ptr;
	}
	flows::addedge(0,2,extraflow,0);
	flows::addedge(5,3,extraflow,0);
	flows::mincostflow();
	if(flows::flow==extraflow+tot)
		return INF*(LL)tot-flows::cost;
	return 0ll;
}
int main(){
	int i,j,k;
	scanf("%d",&n);
	for(i=0;i<n;++i){
		scanf("%d%d%lld",x+i,y+i,v+i);
		--x[i];--y[i];
		px[i]=i;
		py[i]=i;
	}
	scanf("%d",&m);
	for(i=0;i<m;++i){
		TP[i]=readch();
		scanf("%d%d",D+i,V+i);
		--D[i];
	}
	sort(px,px+n,cmpx);
	sort(py,py+n,cmpy);
	LL res=0ll;
	for(i=1;i<=n;++i){
		res=max(res,solve(i));
	}
	printf("%lld\n",res);
	return 0;
}

Measured memory_bytes: 384