#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
const int S=0,T=1,SS=2,TT=3,siz=100;
const long long inf=1000000000000000ll;
int n,m,x[110],y[110],r[400][3],d[400];
long long v[110],ans;
struct bian
{
	int nxt,to,f;
	long long w;
}bi[10010];
int head[220],num;
void add(int from,int to,int f,long long w)
{
	bi[++num].nxt=head[from];
	head[from]=num;
	bi[num].to=to;
	bi[num].f=f;
	bi[num].w=w;
}
void ADD(int from,int to,int f,long long w){add(from,to,f,w),add(to,from,0,-w);}
int lox[110],hix[110],loy[110],hiy[110];
queue<int>q;
long long dis[220];
int fb[220];
bool in[220];
/*void bfs(int s)
{
	q.push(s);fb[s]=0;
	memset(dis,-1,sizeof(dis));
	dis[s]=0;
	int x,y;
	while(!q.empty())
	{
		x=q.front();q.pop();
	//	printf("%d %lld\n",x,dis[x]);
		for(int i=head[x];i;i=bi[i].nxt)
			if(bi[i].f)
			{
				y=bi[i].to;
				if(dis[y]==-1)dis[y]=dis[x]+bi[i].w,q.push(y),fb[y]=i;
			}
	}
}*/
bool spfa()
{
	q.push(SS);fb[SS]=0;
	memset(dis,0xc0,sizeof(dis));
	dis[SS]=0;
	int x,y;
	while(!q.empty())
	{
		x=q.front();q.pop();in[x]=0;
	//	printf("%d %lld\n",x,dis[x]);
		for(int i=head[x];i;i=bi[i].nxt)
			if(bi[i].f)
			{
				y=bi[i].to;
				if(dis[x]+bi[i].w>dis[y])
				{
				//	printf("u %d %d\n",x,y);
					dis[y]=dis[x]+bi[i].w;
					fb[y]=i;
					if(!in[y])in[y]=1,q.push(y);
				}
			}
	}
	return dis[TT]!=0xc0c0c0c0c0c0c0c0ll;
}
void solve(int cnt)
{
//	printf("%d:\n",cnt);
	num=1;
	memset(head,0,sizeof(head));
	memset(d,0,sizeof(d));
	for(int i=1;i<=siz;++i)lox[i]=loy[i]=0,hix[i]=hiy[i]=cnt;
	for(int i=1;i<=m;++i)
		if(r[i][0]=='L')hix[r[i][1]]=r[i][2];
		else if(r[i][0]=='R')lox[r[i][1]-1]=cnt-r[i][2]>0?cnt-r[i][2]:0;
		else if(r[i][0]=='D')hiy[r[i][1]]=r[i][2];
		else loy[r[i][1]-1]=cnt-r[i][2]>0?cnt-r[i][2]:0;
/*	for(int i=siz-1;i;--i)
	{
		if(lox[i+1]>lox[i])lox[i]=lox[i+1];
		if(hix[i+1]<hix[i])hix[i]=hix[i+1];
	}
	for(int i=2;i<=siz;++i)
	{
		if(loy[i-1]>loy[i])loy[i]=loy[i-1];
		if(hiy[i-1]<hiy[i])hiy[i]=hiy[i-1];
	}*/
/*	for(int i=1;i<=siz;++i)printf("%d ",lox[i]);printf("\n");
	for(int i=1;i<=siz;++i)printf("%d ",hix[i]);printf("\n");
	for(int i=1;i<=siz;++i)printf("%d ",loy[i]);printf("\n");
	for(int i=1;i<=siz;++i)printf("%d ",hiy[i]);printf("\n");	*/
	for(int i=1;i<=siz;++i)
	{
		if(lox[i]>hix[i])return;
		d[3+i]+=lox[i];
		if(i<siz)d[4+i]-=lox[i],ADD(4+i,3+i,hix[i]-lox[i],0);
		else d[S]-=lox[i],ADD(S,3+i,hix[i]-lox[i],0);
	}
	for(int i=1;i<=siz;++i)
	{
		if(loy[i]>hiy[i])return;
		d[3+siz+i]-=loy[i];
		if(i<siz)d[4+siz+i]+=loy[i],ADD(3+siz+i,4+siz+i,hiy[i]-loy[i],0);
		else d[T]+=loy[i],ADD(3+siz+i,T,hiy[i]-loy[i],0);
	}
	for(int i=1;i<=n;++i)ADD(3+x[i],3+siz+y[i],1,v[i]);
	d[S]+=cnt,d[T]-=cnt;
	int sum=0;
	long long cost=0;
	for(int i=0;i<=2*siz+3;++i)
		if(d[i]>0)ADD(SS,i,d[i],0),sum+=d[i];
		else if(d[i]<0)ADD(i,TT,-d[i],0);
//	ADD(T,S,0x3f3f3f3f,0);
//	for(int i=0;i<=2*siz+3;++i)
//		for(int j=head[i];j;j=bi[j].nxt)
//			if(bi[j].f)printf("%d %d %d %lld\n",i,bi[j].to,bi[j].f,bi[j].w);
	while(spfa())
	{
	//	bfs(SS);
	//	if(dis[TT]==-1)break;
		--sum;cost+=dis[TT];
		int x=TT;
		while(x!=SS)--bi[fb[x]].f,++bi[fb[x]^1].f,x=bi[fb[x]^1].to;
	}
//	printf("%d\n",sum);
//	bi[head[S]].f=0,bi[head[T]].f=0;
	if(sum)return;
/*	while(1)
	{
		spfa(S);
		if(dis[T]<=0)break;
	//	printf("%lld\n",dis[T]);
		cost+=dis[T];
		int x=T;
		while(x!=S)--bi[fb[x]].f,++bi[fb[x]^1].f,x=bi[fb[x]^1].to;
	}*/
//	printf("%lld\n",cost);
//	printf("%lld\n",cost+cnt*inf);
	ans=max(ans,cost);
}
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",&r[i][0],&r[i][1],&r[i][2]);
	for(int i=1;i<=n;++i)solve(i);
	printf("%lld",ans);
	return 0;
}
