#include<bits/stdc++.h>
using namespace std;

typedef long long lint;
typedef long double louble;

#define so(a) ((int)((a).size()))

template<typename T1,typename T2> inline T1 max(T1 a,T2 b){return a<b?b:a;}
template<typename T1,typename T2> inline T1 min(T1 a,T2 b){return a<b?a:b;}

const char lf = '\n';

namespace ae86
{
	const int bufl = 1 << 15;

	char buf[bufl],*s=buf,*t=buf;

	inline int fetch()
	{
		if(s==t){t=(s=buf)+fread(buf,1,bufl,stdin);if(s==t)return EOF;}
		return *s++;
	}

	inline lint ty()
	{
		lint a=0;int b=1,c=fetch();
		while(!isdigit(c))b^=c=='-',c=fetch();
		while(isdigit(c))a=a*10+c-48,c=fetch();
		return b?a:-a;
	}

	inline int tc()
	{
		int c=fetch();
		while(c<=32 && c!=EOF)c=fetch();
		return c;
	}
}
using ae86::ty;
using ae86::tc;

const int _ = 407 , inf = 0x3f3f3f3f;
const lint V = 1e16 , linf = 0x3f3f3f3f3f3f3f3f;

struct costflow
{
	static const int _n = _ , _e = _ * 9999;

	int to[_e],ne[_e],he[_n],ecnt;
	lint ev[_e],ec[_e];

	void adde(int a,int b,lint c,lint d){to[++ecnt]=b,ev[ecnt]=c,ec[ecnt]=d,ne[ecnt]=he[a],he[a]=ecnt;}
	void addde(int a,int b,lint c,lint d){adde(a,b,c,d),adde(b,a,0,-d);}

	int S,T,ed[_n],dcnt;
	lint dis[_n];int pv[_n],pe[_n];
	
	int bfs()
	{
		memset(dis,63,sizeof(lint)*(dcnt+2));
		memset(pv,0,sizeof(int)*(dcnt+2));
		memset(pe,0,sizeof(int)*(dcnt+2));
		memset(ed,0,sizeof(int)*(dcnt+2));
		
		queue<int> q;
		dis[S]=0,ed[S]=1,q.emplace(S);
		while(!q.empty())
		{
			int a=q.front();
			q.pop(),ed[a]=0;
			for(int i=he[a];i;i=ne[i])
			{
				if(!ev[i])continue;
				int b=to[i];
				if(dis[a]+ec[i]>=dis[b])continue;
				dis[b]=dis[a]+ec[i],pe[b]=i,pv[b]=a;
				if(!ed[b])q.emplace(b),ed[b]=1;
			}
		}
		
		return dis[T]<linf;
	}

	pair<lint,lint> run(int s,int t)
	{
		S=s,T=t;
		lint sflw=0,scos=0;
		while(bfs())
		{
			lint dlt=linf;
			for(int i=T;i!=S;i=pv[i])dlt=min(dlt,ev[pe[i]]);
			sflw+=dlt,scos+=dis[T]*dlt;
			for(int i=T;i!=S;i=pv[i])ev[pe[i]]-=dlt,ev[pe[i]^1]+=dlt;
		}
		return make_pair(sflw,scos);
	}
	
	void cls()
	{
		memset(he,0,sizeof(he)),ecnt=1,dcnt=0;
	}
}f;

int n,m,px[_],py[_];lint pv[_];
int dir[_]={0},loc[_]={0},lim[_]={0};

int ll[_],rr[_],uu[_],dd[_];

lint finder(int tar)
{
	f.cls();

	for(int i=1;i<=tar;i++)ll[i]=dd[i]=0,rr[i]=uu[i]=inf;
	for(int i=1;i<=m;i++)
	{
		if(lim[i]>=tar)continue;
		if(dir[i]=='L')ll[lim[i]+1]=loc[i]+1;
		if(dir[i]=='R')rr[tar-lim[i]]=loc[i]-1;
		if(dir[i]=='D')dd[lim[i]+1]=loc[i]+1;
		if(dir[i]=='U')uu[tar-lim[i]]=loc[i]-1;
	}

	for(int i=2;i<=tar;i++)ll[i]=max(ll[i],ll[i-1]),dd[i]=max(dd[i],dd[i-1]);
	for(int i=tar-1;i>=1;i--)rr[i]=min(rr[i],rr[i+1]),uu[i]=min(uu[i],uu[i+1]);

	f.dcnt=n+n+tar+tar;
	int s=++f.dcnt,t=++f.dcnt;

	for(int i=1;i<=n;i++)f.addde(i,n+i,1,-pv[i]-V);
	for(int i=1;i<=tar;i++)
	{
		f.addde(s,n+n+i,1,0),f.addde(n+n+tar+i,t,1,0);
		for(int j=1;j<=n;j++)
		{
			if(ll[i]<=px[j] && px[j]<=rr[i])f.addde(n+n+i,j,1,0);
			if(dd[i]<=py[j] && py[j]<=uu[i])f.addde(n+j,n+n+tar+i,1,0);
		}
	}

	auto res=f.run(s,t);
	if(res.first<tar)return -1;
	return -res.second-V*tar;
}

int main()
{
	ios::sync_with_stdio(0),cout.tie(nullptr);

	n=ty();
	for(int i=1;i<=n;i++)px[i]=ty(),py[i]=ty(),pv[i]=ty();
	m=ty();
	for(int i=1;i<=m;i++)dir[i]=tc(),loc[i]=ty(),lim[i]=ty();
	
	lint ans=0;
	for(int i=1;i<=n;i++)ans=max(ans,finder(i));
	cout<<ans<<lf;
	
	return 0;
}


Measured memory_bytes: 6528