#include<bits/stdc++.h>
#define LL long long

using namespace std;
const int N=105,NN=N<<1,M=N*N;
const LL inf=1ll<<55;
LL rd()
{
    LL x=0,w=1;char ch=0;
    while(ch<'0'||ch>'9'){if(ch=='-') w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+(ch^48);ch=getchar();}
    return x*w;
}
struct node
{
	LL x,y;
	node(LL nx=0,LL ny=0){x=nx,y=ny;}
	bool operator < (const node &bb) const {return x!=bb.x?x<bb.x:y<bb.y;}
	node operator + (const node &bb) const {return (node){x+bb.x,y+bb.y};}
}w[M],di[NN];
int to[M],nt[M],c[M],hd[NN],tot=1,ps,pt,fw[NN],pr[NN],v[NN];
LL s1,s2,ans;
void adde(int x,int y,int z,LL z1,LL z2)
{
	++tot,to[tot]=y,nt[tot]=hd[x],c[tot]=z,w[tot]=(node){+z1,+z2},hd[x]=tot;
	++tot,to[tot]=x,nt[tot]=hd[y],c[tot]=0,w[tot]=(node){-z1,-z2},hd[y]=tot;
	s1-=z*z1;
}
void csfl()
{
	queue<int> q;
	while(1)
	{
		for(int i=1;i<=pt;++i) di[i]=(node){-inf,-inf};
		di[ps]=(node){0,0},fw[ps]=1<<30,v[ps]=1,q.push(ps);
		fw[pt]=0;
		while(!q.empty())
		{
			int x=q.front();
			q.pop();
			for(int i=hd[x];i;i=nt[i])
			{
				int y=to[i];
				if(c[i]>0&&di[y]<di[x]+w[i])
				{
					di[y]=di[x]+w[i];
					pr[y]=i,fw[y]=min(fw[x],c[i]);
					if(!v[y]) v[y]=1,q.push(y);
				}
			}
			v[x]=0;
		}
		if(!fw[pt]) return;
		s1+=di[pt].x*fw[pt],s2+=di[pt].y*fw[pt];
		int x=pt;
		while(x!=ps)
		{
			int i=pr[x];
			c[i]-=fw[pt],c[i^1]+=fw[pt];
			x=to[i^1];
		}
	}
}
int n,m,t=100;
char cc[2];
LL a[N][3],b[N<<2][3],px[N][2],py[N][2];
map<char,int> id;

int main()
{
/////
	id['L']=0,id['R']=1,id['D']=2,id['U']=3;
	n=rd();
	for(int i=1;i<=n;++i)
		for(int j=0;j<=2;++j)
			a[i][j]=rd();
	m=rd();
	for(int i=1;i<=m;++i)
	{
		scanf("%s",cc),b[i][0]=id[cc[0]];
		b[i][1]=rd(),b[i][2]=rd();
	}
	ps=0,pt=203;
	int yyb=201,zsy=202;
	for(int h=1;h<=n;++h)
	{
		memset(hd,0,sizeof(int)*(pt+1)),tot=1,s1=s2=0;
		for(int i=1;i<=t;++i) px[i][0]=0,px[i][1]=1<<30;
		for(int i=1;i<=t;++i) py[i][0]=0,py[i][1]=1<<30;
		for(int i=1;i<=m;++i)
		{
			if(b[i][0]==0) px[b[i][1]][1]=min(px[b[i][1]][1],b[i][2]);
			if(b[i][0]==1) px[b[i][1]-1][0]=max(px[b[i][1]-1][0],h-b[i][2]);
			if(b[i][0]==2) py[b[i][1]][1]=min(py[b[i][1]][1],b[i][2]);
			if(b[i][0]==3) py[b[i][1]-1][0]=max(py[b[i][1]-1][0],h-b[i][2]);
		}
		adde(ps,yyb,h,1,0);
		bool o=1;
		int np=yyb;
		for(int i=t;i;--i)
		{
			if(px[i][0]>px[i][1]){o=0;break;}
			adde(np,i,px[i][0],1,0),adde(np,i,px[i][1]-px[i][0],0,0);
			np=i;
		}
		np=zsy;
		for(int i=t;i;--i)
		{
			if(py[i][0]>py[i][1]){o=0;break;}
			adde(i+t,np,py[i][0],1,0),adde(i+t,np,py[i][1]-py[i][0],0,0);
			np=i+t;
		}
		adde(zsy,pt,h,1,0);
		if(!o) continue;
		for(int i=1;i<=n;++i) adde(a[i][0],a[i][1]+t,1,0,a[i][2]);
		csfl();
		if(s1>=0) ans=max(ans,s2);
	}
	printf("%lld\n",ans);
    return 0;
}
