#include<bits/stdc++.h>
#define cmin(a,b) (a>(b)?a=(b),1:0)
#define cmax(a,b) (a<(b)?a=(b),1:0)
#define dmin(a,b) ((a)<(b)?(a):(b))
#define dmax(a,b) ((a)>(b)?(a):(b))
namespace io
{
	int F()
	{
		 int F=1,n=0;
		 char ch;
		 while((ch=getchar())!='-'&&(ch<'0'||ch>'9'));
		 ch=='-'?F=0:n=ch-'0';
		 while((ch=getchar())>='0'&&ch<='9')n=n*10+ch-'0';
		 return F?n:-n;
	}
	long long G()
	{
		 long long F=1,n=0;
		 char ch;
		 while((ch=getchar())!='-'&&(ch<'0'||ch>'9'));
		 ch=='-'?F=0:n=ch-'0';
		 while((ch=getchar())>='0'&&ch<='9')n=n*10+ch-'0';
		 return F?n:-n;
	}
}
struct edge
{
	int to;
	long long val;
	int res;
	int next;
}e[3888];
int pe=222;
void insert(int a,int to,long long val,int cap)
{
	e[pe]=(edge){to,val,cap,e[a].next};
	e[a].next=pe++;
}
void addedge(int a,int to,long long val,int cap)
{
	insert(a,to,val,cap);
	insert(to,a,-val,0);
}
int S,T;
int U[222],D[222],L[222],R[222];
int x[222],y[222];
long long v[222];
int in[222];
int q[22222222],hq,tq;
int vis[2222];
long long dis[2222];
int from[2222],frome[2222];
int flow;
bool spfa()
{
	for(int i=1;i<=T;++i)dis[i]=0x6e6e6e6e6e6e6e6ell;
	for(q[hq=1]=S,tq=2,vis[S]=1,dis[S]=0;hq!=tq;vis[q[hq++]]=0)
		for(register int p=e[q[hq]].next;p;p=e[p].next)
			if(e[p].res&&cmin(dis[e[p].to],dis[q[hq]]+e[p].val))
			{
				from[e[p].to]=q[hq],frome[e[p].to]=p;
				if(!vis[e[p].to])vis[e[p].to]=1,q[tq++]=e[p].to;
			}
	return dis[T]!=0x6e6e6e6e6e6e6e6ell;
}
long long ek()
{
	flow=0;
	long long ans=0;
	while(spfa())
	{
		int now=T;
		int min=0x3f3f3f3f;
		while(1)
		{
			cmin(min,e[frome[now]].res);
			now=from[now];
			if(now==S)break;
		}
		now=T;
		while(1)
		{
			e[frome[now]].res-=min;
			e[frome[now]^1].res+=min;
			now=from[now];
			if(now==S)break;
		}
		ans+=dis[T]*min;
		flow+=min;
	}
	return ans;
}
int main()
{
	int n=io::F();
	for(register int i=1;i<=n;++i)
		x[i]=io::F(),y[i]=io::F(),v[i]=io::G();
	int m=io::F();
	for(register int i=1;i<=100;++i)U[i]=L[i]=D[i]=R[i]=-1;
	for(register int i=1;i<=m;++i)
	{
		char s[4];
		scanf("%s",s);
		int a=io::F(),b=io::F();
		if(*s=='U')U[a]=b;
		if(*s=='D')D[a]=b;
		if(*s=='L')L[a]=b;
		if(*s=='R')R[a]=b;
	}
	for(register int i=1;i<=100;++i)
	{
		if(U[i]==-1)U[i]=n;
		if(D[i]==-1)D[i]=n;
		if(L[i]==-1)L[i]=n;
		if(R[i]==-1)R[i]=n;
	}
	S=201,T=202;
	long long max=0;
	int sum;
	long long tmp;
	for(register int s=1;s<=n;++s)
	{
		for(register int j=1;j<=T;++j)e[j].next=0,in[j]=0;
		pe=222;
		if(s>R[1])goto skip;
		if(s>L[100])goto skip;
		if(s>U[1])goto skip;
		if(s>D[100])goto skip;
		for(register int i=1;i<100;++i)
		{
			int lb,rb;
			rb=R[i+1],lb=s-L[i];
			if(lb>rb)goto skip;
			addedge(i,i+1,0,rb-lb);
			in[i+1]+=lb;
			in[i]-=lb;
			
			rb=D[i],lb=s-U[i+1];
			if(lb>rb)goto skip;
			addedge(i+100,i+101,0,rb-lb);
			in[i+101]+=lb;
			in[i+100]-=lb;
		}
		{
			in[1]+=s;
			in[200]-=s;
		}
		sum=0;
		for(register int i=1;i<=200;++i)
			if(in[i]>0)addedge(S,i,0,in[i]),sum+=in[i];
				else if(in[i]<0)addedge(i,T,0,-in[i]);
		for(register int i=1;i<=n;++i)
			addedge(x[i],y[i]+100,-v[i],1);
		tmp=-ek();
		if(flow!=sum)continue;
		cmax(max,tmp);
		skip:;
	}
	printf("%lld\n",max);
	return 0;
}
