#include<bits/stdc++.h>
#define LL long long
#define ull unsigned long long
#define ULL ull
#define mp make_pair
#define pii pair<int,int>
#define piii pair<int, pii >
#define pll pair <ll,ll>
#define pb push_back
#define big 20160116
#define pq priority_queue
#define rank rk124232
#define y1 y20160116
#define y0 y20160110
using namespace std;
#ifndef MY
	#define putchar IO::_putchar
	#define getchar IO::_getchar
#endif
namespace IO
{
    const int sz=1<<15;
    char inbuf[sz],outbuf[sz];
    char *pinbuf=inbuf+sz;
    char *poutbuf=outbuf;
    inline char _getchar()
    {
        if (pinbuf==inbuf+sz)fread(inbuf,1,sz,stdin),pinbuf=inbuf;
        return *(pinbuf++);
    }
    inline void _putchar(char x)
    {
        if (poutbuf==outbuf+sz)fwrite(outbuf,1,sz,stdout),poutbuf=outbuf;
        *(poutbuf++)=x;
    }
    inline void flush()
    {
        if (poutbuf!=outbuf)fwrite(outbuf,1,poutbuf-outbuf,stdout),poutbuf=outbuf;
    }
}
inline int read()
{
    int x=0,p=1;
	char c=getchar();
    while (c<'0' || c>'9'){
    	if (c=='-') p=-1;
    	c=getchar();
	}
    while (c>='0' && c<='9') x=x*10+c-48,c=getchar();
    return x*p;
}
const int Maxn=555;
int n,m;
int l1[Maxn],l2[Maxn],r1[Maxn],r2[Maxn];
int x[Maxn],y[Maxn];
char tp[Maxn],A[Maxn],B[Maxn];
LL v[Maxn];
struct edge{
	int to,cap,rev;
	LL cost;
	edge(int _to,int _cap,LL _cost,int _rev){
		to=_to;cap=_cap,cost=_cost;rev=_rev;
	}
	edge(){
		;
	}
};
vector<edge> G[Maxn];
LL dist[Maxn];
int preve[Maxn],prevv[Maxn],vis[Maxn];
int q[Maxn*Maxn],sq,eq;
int s=553,t=554;
const LL INF=4e16;
void add_edge(int u,int v,int ca,LL co){
	G[u].pb(edge(v,ca,co,G[v].size()));
	G[v].pb(edge(u,0,-co,G[u].size()-1));
}
LL Bas=0;
void Add_edge(int u,int v,int lo,int hi,LL co){
	add_edge(u,v,hi-lo,co);
	add_edge(u,v,lo,co-INF);
	Bas+=INF*lo;
}
void Clear(){
	for (int i=0;i<Maxn;i++){
		G[i].clear();dist[i]=0;vis[i]=0;
	}
}
bool bad=false;
LL MCF(int f){
	LL ret=0;
	while (1){
		if (!f) break;
		for (int i=0;i<Maxn;i++) dist[i]=9e18,vis[i]=0;
		sq=eq=0;
		dist[s]=0;q[eq++]=s;vis[s]=true;
		while (sq<eq){
			int x=q[sq++];
			vis[x]=false;
			for (int i=0;i<G[x].size();i++){
				if (G[x][i].cap){
					int v=G[x][i].to;
					if (dist[v]>dist[x]+G[x][i].cost){
						dist[v]=dist[x]+G[x][i].cost;
						prevv[v]=x;preve[v]=i;
						if (!vis[v]){
							q[eq++]=v;
							vis[v]=true;
						}
					}
				}
			}
		}
	//	assert(dist[s]==0);
	//	cout<<"FF"<<' '<<dist[t]<<endl; 
		if (dist[t]==9e18){
			bad=true;
			break;
		}
		
		if (dist[t]>0) return ret;
		int Fl=f;
		for (int i=t;i!=s;i=prevv[i]){
		//	cout<<i<<endl;
			Fl=min(Fl,G[prevv[i]][preve[i]].cap);
		}
		ret+=dist[t]*Fl;
		for (int i=t;i!=s;i=prevv[i]){
			edge &e=G[prevv[i]][preve[i]];
			e.cap-=Fl;
			G[i][e.rev].cap+=Fl;
		}
		f-=Fl;
	//	cout<<"EE"<<endl;
	}
	return ret;
}
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++){
		scanf("%d %d %lld",&x[i],&y[i],&v[i]);
	}
	scanf("%d",&m);
	for (int i=1;i<=m;i++){
		scanf(" %c %d %d",&tp[i],&A[i],&B[i]);
	}
	LL ans=0;
	for (int _=1;_<=n;_++){
	//	cerr<<_<<endl;
		Clear();
		Bas=0;
		for (int i=1;i<=101;i++){
			l1[i]=l2[i]=0;r1[i]=r2[i]=n;
		} 
		for (int i=1;i<=m;i++){
			if (tp[i]=='L'){
				r1[A[i]]=B[i];
			}
			else if (tp[i]=='R'){
				l1[A[i]-1]=max(0,_-B[i]);
			}
			else if (tp[i]=='D'){
				r2[A[i]]=B[i];
			}
			else{
				l2[A[i]-1]=max(0,_-B[i]);
			}
		}
		if (l1[0] || l2[0]) continue;
		for (int i=1;i<=100;i++){
			l1[i]=max(l1[i],l1[i-1]);
			l2[i]=max(l2[i],l2[i-1]);
		}
		for (int i=100;i>=1;i--){
			r1[i]=min(r1[i],r1[i+1]);
			r2[i]=min(r2[i],r2[i+1]);
		}
		Add_edge(s,100,l1[100],r1[100],0);
		for (int i=100;i>1;i--){
			Add_edge(i,i-1,l1[i-1],r1[i-1],0);
		}
		Add_edge(200,t,l2[100],r2[100],0);
		for (int i=100;i>1;i--){
			Add_edge(i+99,i+100,l2[i-1],r2[i-1],0);
		}
		int kc=200;
		for (int i=1;i<=n;i++){
			add_edge(x[i],i+kc,1,-v[i]);
			add_edge(i+kc,y[i]+100,1,0);
		}// cerr<<_<<endl;
		bad=false;
		LL Res=MCF(_);
		if (bad) continue;
		//cerr<<_<<endl;
		bool flag=true;
		for (int i=0;i<Maxn;i++){
			for (int j=0;j<G[i].size();j++){
				if (G[i][j].cost==-INF){
				//	cout<<"HHHHHHHHHHH"<<endl;
					if (G[i][j].cap) flag=false;
				}
			}
		}
		
		if (!flag) continue;
	//	cout<<"F"<<" "<<_<<' '<<Res<<' '<<Bas<<endl;
		ans=min(ans,Res+Bas);
	}
	printf("%lld\n",-ans);
	return 0;
}


Measured memory_bytes: 384