#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=505,M=2e5+5,inf=1<<30;
int head[N],nxt[M],to[M],wei[M],tot=1,s,t,n,m,x[N],y[N],a[N],b[N],lx[N],rx[N],ly[N],ry[N];
ll cost[M],dis[N],v[N],res,ans; char op[N][2]; bool vis[N];
void adde(int u, int v, ll c=0, int w=1)
{
	nxt[++tot]=head[u],head[u]=tot,to[tot]=v,wei[tot]=w,cost[tot]=-c;
	nxt[++tot]=head[v],head[v]=tot,to[tot]=u,wei[tot]=0,cost[tot]=c;
}
bool spfa()
{
	memset(vis,0,sizeof(bool)*(t+3));
	memset(dis,0x3f,sizeof(ll)*(t+3));
	queue<int> q;
	dis[t]=0,q.push(t);
	while(!q.empty())
	{
		int u=q.front();
		vis[u]=false,q.pop();
		for(int e=head[u];e;e=nxt[e])
			if(wei[e^1]&&dis[to[e]]>dis[u]-cost[e])
			{
				dis[to[e]]=dis[u]-cost[e];
				if(!vis[to[e]]) vis[to[e]]=true,q.push(to[e]);
			}
	}
	return dis[s]!=dis[0];
}
int dfs(int u, int mx)
{
	vis[u]=true;
	if(u==t) return mx;
	int l=mx;
	for(int e=head[u];e&&l;e=nxt[e])
		if(!vis[to[e]]&&wei[e]>0&&dis[to[e]]==dis[u]-cost[e])
		{
			int f=dfs(to[e],min(l,wei[e]));
			res+=1ll*f*cost[e];
			l-=f,wei[e]-=f,wei[e^1]+=f;
		}
	return mx-l;
}
ll exec()
{
	res=0;
	while(spfa())
		do
		{
			memset(vis,0,sizeof(bool)*(t+3));
			dfs(s,inf);
		} while(vis[t]);
	return -res;
}
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("%s%d%d",op[i],&a[i],&b[i]);
	for(int k=1;k<=n;++k)
	{
		memset(head,0,sizeof(head)),tot=1;
		s=(n+k)*2+1,t=s+1;
		for(int i=1;i<=k;++i) adde(s,i),adde(i+k+2*n,t),lx[i]=ly[i]=0,rx[i]=ry[i]=inf;
		for(int i=1;i<=n;++i) adde(i+k,i+n+k,v[i]);
		for(int i=1;i<=m;++i)
		{
			if(op[i][0]=='L')
				for(int j=b[i]+1;j<=k;++j) lx[j]=max(lx[j],a[i]+1);
			if(op[i][0]=='R')
				for(int j=1;j<=k-b[i];++j) rx[j]=min(rx[j],a[i]-1);
			if(op[i][0]=='D')
				for(int j=b[i]+1;j<=k;++j) ly[j]=max(ly[j],a[i]+1);
			if(op[i][0]=='U')
				for(int j=1;j<=k-b[i];++j) ry[j]=min(ry[j],a[i]-1);
		}
		for(int i=1;i<=k;++i)
			for(int j=1;j<=n;++j)
			{
				if(lx[i]<=x[j]&&x[j]<=rx[i]) adde(i,j+k);
				if(ly[i]<=y[j]&&y[j]<=ry[i]) adde(j+k+n,i+k+2*n);
			}
		ans=max(ans,exec());
	}
	printf("%lld\n",ans);
}
