#include<bits/stdc++.h>
using namespace std;
#define nn 808
#define ll long long 

namespace ene{
	vector<ll> v[nn],cap[nn],cost[nn],rev[nn];
	void clear()
	{
		for(ll i=0;i<nn;i++) v[i].clear(),cap[i].clear(),cost[i].clear(),rev[i].clear();
	}
	void link(ll x,ll y,ll c,ll d)
	{
		rev[x].push_back(v[y].size());rev[y].push_back(v[x].size());
		v[x].push_back(y);v[y].push_back(x);
		cap[x].push_back(c);cap[y].push_back(0);
		cost[x].push_back(d);cost[y].push_back(-d);
	}
	
	ll ss;ll vis[nn];
	ll prex[nn],prei[nn];ll dist[nn];
	void spfa(ll s)
	{
		for(ll i=0;i<nn;i++) dist[i]=-1e18;
		queue<ll> q;q.push(s);dist[s]=0;vis[s]=1;
		while(q.size())
		{
			ll x=q.front();q.pop();vis[x]=0;
			for(ll i=0;i<v[x].size();i++)
			{
				ll y=v[x][i];
				if(dist[y]<dist[x]+cost[x][i] and cap[x][i])
				{
					dist[y]=dist[x]+cost[x][i],prex[y]=x,prei[y]=i;
					if(!vis[y]) q.push(y);vis[y]=1;
				}
			}
		}
	}
	ll dfs(ll y,ll f)
	{
		if(y==ss) return f;
		ll x=prex[y],i=prei[y],j=rev[x][i];
		f=dfs(x,min(f,cap[x][i]));
		cap[x][i]-=f,cap[y][j]+=f;
		return f;
	}
	ll solve(ll s,ll t,ll n)
	{
		ss=s;ll ans=0;
		while(1)
		{
			spfa(s);if(dist[t]<-1e17) break;
			ll tp=dfs(t,1e18);
			tp=min(tp,n);n-=tp;
			ans+=tp*dist[t];
		}
		if(n) return -1e18;
		return ans;
	}

};

ll n,m;
ll xans[nn],yans[nn];ll val[nn];
ll s=nn-1,t=nn-2;
ll morex[nn],morey[nn],lessx[nn],lessy[nn];
char str[nn][3];ll xx[nn],kk[nn];
ll output=0;
void solve(ll guess)
{
	ene::clear();set<ll> sx,sy;map<ll,ll> mx,my;
	for(ll i=1;i<=n;i++) sx.insert(xans[i]),sy.insert(yans[i]);	
	
	sx.insert(1e16),sy.insert(1e16);
	
	ll tot=0;ll xn,yn;
	for(set<ll>::iterator it=sx.begin();it!=sx.end();it++) mx[*it]=++tot;xn=tot;
	for(set<ll>::iterator it=sy.begin();it!=sy.end();it++) my[*it]=++tot;yn=tot;
	
	for(ll i=1;i<=n;i++) ene::link(mx[xans[i]],my[yans[i]],1,val[i]);
	
	memset(morex,0x3f,sizeof morex);memset(morey,0x3f,sizeof morey);
	memset(lessx,0,sizeof lessx);memset(lessy,0,sizeof lessy);
	
	for(ll i=1;i<=m;i++)
	{
		ll x=xx[i],k=kk[i];
		if(str[i][0]=='R')
		{
			k++;
			ll tx=*sx.lower_bound(x);
			if(k<=xn)morex[k]=min(morex[k],mx[tx]-1);
		}
		else if(str[i][0]=='U')
		{
			k++;k+=xn;
			ll ty=*sy.lower_bound(x);
			if(k<=yn)morey[k]=min(morey[k],my[ty]-1);
		}
		else if(str[i][0]=='L')
		{
			k=guess-k;
			ll tx=*sx.upper_bound(x);
			if(k>=1)lessx[k]=max(lessx[k],mx[tx]);
		}
		else if(str[i][0]=='D')
		{
			k=guess-k;k+=xn;
			ll ty=*sy.upper_bound(x);
			if(k>=xn+1)lessy[k]=max(lessy[k],my[ty]);
		}
	}
	
		
	for(ll i=2;i<=xn;i++) morex[i]=min(morex[i-1],morex[i]);
	for(ll i=xn;i>=2;i--) lessx[i-1]=max(lessx[i-1],lessx[i]); 
	for(ll i=xn+2;i<=yn;i++) morey[i]=min(morey[i-1],morey[i]);
	for(ll i=yn;i>=xn+2;i--) lessy[i-1]=max(lessy[i-1],lessy[i]);
	//cout<<lessx[2]<<"\n";
	for(ll i=1;i<=guess;i++)
	{
		++tot;ene::link(s,tot,1,0);
		for(ll j=1;j<=xn;j++)
			if(j>=lessx[i] and j<=morex[i])
				ene::link(tot,j,1,0);
	}
	for(ll i=xn+1;i<=xn+guess;i++)
	{
		++tot;ene::link(tot,t,1,0);
		for(ll j=xn+1;j<=yn;j++)
			if(j>=lessy[i] and j<=morey[i])
				ene::link(j,tot,1,0);
	}
	
//	if(output>0) cout<<guess<<"\n";
	output=max(output,ene::solve(s,t,guess));
}

signed main()
{
	scanf("%lld",&n);for(ll i=1;i<=n;i++) scanf("%lld%lld%lld",&xans[i],&yans[i],&val[i]);
	scanf("%lld",&m);for(ll i=1;i<=m;i++) scanf("%s%lld%lld",str[i],&xx[i],&kk[i]);
	
	for(ll i=1;i<=n;i++) solve(i);
	
	cout<<output<<"\n";		
	return 0;
}

Measured memory_bytes: 1536