#include<iostream>
#include<cstdio>
#include<queue>
#define gc getchar()
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define ROF(i,a,b) for(int i=a;i>=b;i--)
#define REP(u) for(int i=hd[u],v,c;v=e[i].v,c=e[i].c,i;i=e[i].n)
using namespace std;
typedef long long ll;
const int N=550,M=100100,iNF=1000010000;
const ll INF=1e18;
int n,m,S,T,X,fl,mxf;
int lc[N],rc[N],uc[N],dc[N],hd[N],in[N],vi[N];
ll mxw,ans,di[N];
char o;
queue<int>qu;
struct vec{int x,y;ll w;}p[N];
struct lim{char o;int t,c;}q[N];
struct edge{int n,v,c;ll w;}e[M];
void add_(int u,int v,ll w,int c){e[++fl]=(edge){hd[u],v,c,w};hd[u]=fl;}
void adde(int u,int v,ll w,int c){add_(u,v,w,c);add_(v,u,-w,0);}
bool SPFA(){
	FOR(i,S,T) di[i]=-INF;
	di[T]=0;qu.push(T);
	while(qu.size()){
		int u=qu.front();qu.pop();in[u]=0;
		REP(u)if(e[i^1].c && di[v]<di[u]-e[i].w){
			di[v]=di[u]-e[i].w;
			if(!in[v]) qu.push(v),in[v]=1;
		}
	}
	return di[S]>-INF;
}
int dfs(int u,int E){
	vi[u]=1;
	if(u==T) return E;
	int F=0;
	REP(u)if(c && !vi[v] && di[v]==di[u]-e[i].w){
		int t=dfs(v,min(E,c));
		mxw+=e[i].w*t;
		F+=t;e[i^1].c+=t;
		E-=t;e[i^0].c-=t;
		if(!E) break;
	}return F;
}
void work(int k){
	FOR(i,0,k+1) lc[i]=dc[i]=1,rc[i]=uc[i]=X;
	FOR(i,1,m){
		int t=q[i].t,c=q[i].c;
		if(q[i].o=='R'||q[i].o=='U') c=k-c+1;
		if(q[i].o=='L' && 1<=c && c<=k) lc[c]=max(lc[c],t+1);
		if(q[i].o=='R' && 1<=c && c<=k) rc[c]=min(rc[c],t-1);
		if(q[i].o=='D' && 1<=c && c<=k) dc[c]=max(dc[c],t+1);
		if(q[i].o=='U' && 1<=c && c<=k) uc[c]=min(uc[c],t-1);
	}
	S=1;T=2*(k+X+1);fl=1;
	FOR(i,S,T) hd[i]=0;
	FOR(i,1,k) lc[i]=max(lc[i],lc[i-1]),dc[i]=max(dc[i],dc[i-1]);
	ROF(i,k,1) rc[i]=min(rc[i],rc[i+1]),uc[i]=min(uc[i],uc[i+1]);
	FOR(i,1,k){
		adde(S,i<<1|0,0,1);
		adde(i<<1|1,T,0,1);
		FOR(j,lc[i],rc[i]) adde(i<<1|0,(j+k)<<1|0,0,1);
		FOR(j,dc[i],uc[i]) adde((j+k)<<1|1,i<<1|1,0,1);
	}
	FOR(i,1,n) adde((p[i].x+k)<<1|0,(p[i].y+k)<<1|1,p[i].w,1);
	mxw=mxf=0;
	//FOR(x,S,T){cout<<x<<':';REP(x) cout<<v<<' ';cout<<'\n';}
	while(SPFA()){
		do{
			FOR(i,S,T) vi[i]=0;
			mxf+=dfs(S,iNF);
		}while(vi[T]);
	}
	if(mxf==k) ans=max(ans,mxw);
}
int main(){
	//freopen("1.in","r",stdin);
	scanf("%d",&n);
	FOR(i,1,n) scanf("%d%d%lld",&p[i].x,&p[i].y,&p[i].w);
	FOR(i,1,n) X=max(X,max(p[i].x,p[i].y));
	scanf("%d",&m);
	FOR(i,1,m){
		for(o=gc;o!='L'&&o!='R'&&o!='D'&&o!='U';o=gc);
		q[i].o=o;scanf("%d%d",&q[i].t,&q[i].c),q[i].c++;
	}
	FOR(i,1,n) work(i);
	cout<<ans<<'\n';
}