#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<vector>
#include<set>
#include<map>
using std::cin;using std::cerr;
using std::max;using std::min;
#define N 400
#define inf 1e18
#define ll long long
#define db double
#define dbg1(x) cerr<<#x<<"="<<(x)<<" "
#define dbg2(x) cerr<<#x<<"="<<(x)<<"\n"
int n,m,L[N],R[N],D[N],U[N];ll ans;
struct point{int x,y;ll v;}A[N];
struct info{char op;int x,y;}B[N];
class Flow
{
	std::queue<int>q;
	int ecnt,last[N],S,T,inq[N],from[N];ll dist[N];
	struct road{int to,f,nex;ll v;}e[N*N];
	void adde(int u,int v,int w,ll co)
	{
		e[++ecnt]=(road){v,w,last[u],co},last[u]=ecnt;
		e[++ecnt]=(road){u,0,last[v],-co},last[v]=ecnt;
	}
	bool spfa()
	{
		for(int i=S;i<=T;i++) dist[i]=-inf,inq[i]=0;
		for(q.push(S),dist[S]=0;!q.empty();)
		{
			int top=q.front();inq[top]=0,q.pop();
			for(int k=last[top];k;k=e[k].nex)
				if(dist[e[k].to]<dist[top]+e[k].v&&e[k].f)
				{
					dist[e[k].to]=dist[top]+e[k].v,from[e[k].to]=k;
					if(!inq[e[k].to]) inq[e[k].to]=1,q.push(e[k].to);
				}
		}
		return dist[T]>-inf;
	}
	ll mcf()
	{
		for(int k=from[T];k;k=from[e[k^1].to]) e[k].f-=1,e[k^1].f+=1;
		return dist[T];
	}
public:
	void setmap(int x)
	{
		S=0,T=x+n<<1|1,ecnt=1;
		for(int i=S;i<=T;i++) last[i]=0;
		for(int i=1;i<=x;i++)
		{
			adde(S,i,1,0),adde(x+n+n+i,T,1,0);
			for(int j=1;j<=n;j++)
			{
				if(A[j].x>=L[i]&&A[j].x<=R[i]) adde(i,x+j,1,0);
				if(A[j].y>=D[i]&&A[j].y<=U[i]) adde(x+n+j,x+n+n+i,1,0);
			}
		}
		for(int i=1;i<=n;i++) adde(x+i,x+n+i,1,A[i].v);
	}
	ll MaxcostMaxflow() {ll res=0;while(spfa()) res+=mcf();return res;}
}F;
ll Solve(int x)
{
	for(int i=1;i<=x;i++) L[i]=D[i]=0,R[i]=U[i]=999;
	for(int i=1;i<=m;i++) if(B[i].y<x)
	{
		if(B[i].op=='L') L[B[i].y+1]=max(L[B[i].y+1],B[i].x+1);
		if(B[i].op=='R') R[x-B[i].y]=min(R[x-B[i].y],B[i].x-1);
		if(B[i].op=='D') D[B[i].y+1]=max(D[B[i].y+1],B[i].x+1);
		if(B[i].op=='U') U[x-B[i].y]=min(U[x-B[i].y],B[i].x-1);
	}
	for(int i=1;i<=x;i++) L[i]=max(L[i],L[i-1]),D[i]=max(D[i],D[i-1]);
	for(int i=x-1;i;i--) R[i]=min(R[i],R[i+1]),U[i]=min(U[i],U[i+1]);
	for(int i=1;i<=x;i++) if(L[i]>R[i]||D[i]>U[i]) return -inf;
	F.setmap(x);
	return F.MaxcostMaxflow();
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d%d%lld",&A[i].x,&A[i].y,&A[i].v);
	scanf("%d",&m);
	for(int i=1;i<=m;i++) scanf(" %c%d%d",&B[i].op,&B[i].x,&B[i].y);
	for(int i=1;i<=n;i++) ans=max(ans,Solve(i));
	printf("%lld\n",ans);
	return 0;
}