// Author -- Frame

#include<bits/stdc++.h>

#define lowbit(x) ((x)&(-x))
#define Finline __inline__ __attribute__ ((always_inline))
#define DEBUG fprintf(stderr,"Running on Line %d in Function %s\n",__LINE__,__FUNCTION__)
#define SZ(x) ((int)x.size())
#define mkpr std::make_pair
#define pb push_back

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef std::pair<int,int> pi;
typedef std::pair<ll,ll> pl;

const int inf=0x3f3f3f3f,Inf=0x7fffffff;
const ll INF=0x3f3f3f3f3f3f3f3f;

Finline uint rnd()
{
	static uint seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
template <typename _Tp>_Tp gcd(const _Tp &a,const _Tp &b){return (!b)?a:gcd(b,a%b);}
template <typename _Tp>Finline _Tp abs(const _Tp &a){return a>=0?a:-a;}
template <typename _Tp>Finline _Tp max(const _Tp &a,const _Tp &b){return a<b?b:a;}
template <typename _Tp>Finline _Tp min(const _Tp &a,const _Tp &b){return a<b?a:b;}
template <typename _Tp>Finline void chmax(_Tp &a,const _Tp &b){(a<b)&&(a=b);}
template <typename _Tp>Finline void chmin(_Tp &a,const _Tp &b){(b<a)&&(a=b);}
template <typename _Tp>Finline void read(_Tp &x)
{
	char ch(getchar());
	bool f(false);
	while(ch<48||ch>57) f|=ch==45,ch=getchar();
	x=ch&15,ch=getchar();
	while(ch>=48&&ch<=57) x=(((x<<2)+x)<<1)+(ch&15),ch=getchar();
	if(f) x=-x;
}
template <typename _Tp,typename... Args>Finline void read(_Tp &t,Args &...args){read(t);read(args...);}
Finline int read_str(char *s)
{
	char ch(getchar());
	while(ch==' '||ch=='\r'||ch=='\n') ch=getchar();
	char *tar=s;
	*tar=ch,ch=getchar();
	while(ch!=' '&&ch!='\r'&&ch!='\n'&&ch!=EOF) *(++tar)=ch,ch=getchar();
	return tar-s+1;
}

const int N=405;
int x[N],y[N];
ll val[N];
struct edge{
	int v,nxt,w;
	ll cost;
}c[N*N<<3];
int front[N],edge_cnt;
Finline void addedge(int u,int v,int w,ll cost)
{
	c[++edge_cnt]=(edge){v,front[u],w,cost};
	front[u]=edge_cnt;
	
	c[++edge_cnt]=(edge){u,front[v],0,-cost};
	front[v]=edge_cnt;
}
char opt[N];
int C[N],D[N];
int L[N],R[N];
int S,T;
ll dep[N];
int cur[N];
int _q[N*N],_l,_r;
bool inq[N];
bool bfs()
{
	memcpy(cur,front,sizeof(cur));
	memset(dep,63,sizeof(dep));
	memset(inq,0,sizeof(inq));
	_q[_l=_r=1]=S;
	dep[S]=0;
	while(_l!=_r+1)
	{
		int x=_q[_l++];
		inq[x]=false;
		for(int i=front[x];~i;i=c[i].nxt)
		{
			int v=c[i].v;
			if(c[i].w&&dep[v]>dep[x]+c[i].cost)
			{
				dep[v]=dep[x]+c[i].cost;
				if(!inq[v]) inq[v]=true,_q[++_r]=v;
			}
		}
	}
	return dep[T]<INF;
}
int dfs(int x,int flow)
{
	if(x==T||!flow) return flow;
	inq[x]=true;
	int f=0,rf;
	for(int &i=cur[x];~i;i=c[i].nxt)
	{
		if(!inq[c[i].v]&&dep[c[i].v]==dep[x]+c[i].cost&&(rf=dfs(c[i].v,min(flow,c[i].w))))
		{
			flow-=rf,f+=rf;
			c[i].w-=rf,c[i^1].w+=rf;
			if(!flow) return f;
		}
	}
	return f;
}
pl dinic()
{
	int res=0;
	ll ans=0;
	while(bfs())
	{
		int tmp=dfs(S,inf);
		res+=tmp;
		ans+=1ll*tmp*dep[T];
	}
	return mkpr(res,ans);
}
int main()
{
	int n,m;
	read(n);
	for(int i=1;i<=n;++i) read(x[i],y[i],val[i]);
	read(m);
	for(int i=1;i<=m;++i)
	{
		char ch=getchar();
		while(!isalpha(ch)) ch=getchar();
		opt[i]=ch;
		read(C[i],D[i]);
	}
	ll res=0;
	for(int k=1;k<=n;++k)
	{
		edge_cnt=-1;
		memset(front,255,sizeof(front));
		memset(L,-63,sizeof(L)),memset(R,63,sizeof(R));
		for(int i=1;i<=m;++i)
		{
			if(D[i]>=k) continue;
			if(opt[i]=='L') chmax(L[D[i]+1],C[i]+1);
			else if(opt[i]=='R') chmin(R[k-D[i]],C[i]-1);
			else if(opt[i]=='D') chmax(L[D[i]+1+k],C[i]+1);
			else chmin(R[k-D[i]+k],C[i]-1);
		}
		for(int i=2;i<=k;++i) chmax(L[i],L[i-1]);
		for(int i=k-1;i>=1;--i) chmin(R[i],R[i+1]);
		for(int i=k+2;i<=k+k;++i) chmax(L[i],L[i-1]);
		for(int i=k+k-1;i>k;--i) chmin(R[i],R[i+1]);
		S=n+n+k+k+1;
		T=S+1;
		for(int i=1;i<=k;++i)
		{
			addedge(S,i,1,0);
			addedge(i+k,T,1,0);
			for(int j=1;j<=n;++j)
			{
				if(x[j]>=L[i]&&x[j]<=R[i]) addedge(i,j+k+k,1,0);
				if(y[j]>=L[i+k]&&y[j]<=R[i+k]) addedge(j+k+k+n,i+k,1,0);
			}
		}
		for(int i=1;i<=n;++i) addedge(i+k+k,i+k+k+n,1,-val[i]);
		pl ans=dinic();
		if(ans.first==k) chmax(res,-ans.second);
	}
	printf("%lld\n",res);
	return 0;
}


Measured memory_bytes: 4008