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

#define INF int(1e9)
#define Inf ll(1e18) 
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mp make_pair
#define pb push_back
#define fst first
#define snd second
typedef long long ll;
typedef pair<int,int> pii;

const int maxn=605;
const int maxm=maxn*maxn;
int n,m;
char op[maxn],s[maxn];
int a[maxn],b[maxn],x[maxn],y[maxn],lim_mnx[maxn],lim_mxx[maxn],lim_mny[maxn],lim_mxy[maxn];
ll v[maxn];

namespace Flow{
	int tot,S,T,V,ansf;
	bool in[maxn],vis[maxn];
	int head[maxn],nxt[maxm*2],to[maxm*2],cap[maxm*2];
	ll dist[maxn],cost[maxm*2],ansc;
	queue<int>q;
	void init(){
		tot=0;
		memset(head,-1,sizeof(head));
	}
	void addedge(int u,int v,int c,ll co){
		nxt[tot]=head[u];to[tot]=v;cap[tot]=c;cost[tot]=co;head[u]=tot++;
		nxt[tot]=head[v];to[tot]=u;cap[tot]=0;cost[tot]=-co;head[v]=tot++;
	}
	void spfa(){
		rep(i,V)in[i]=false,dist[i]=Inf;
		dist[S]=0;
		in[S]=true;
		q.push(S);
		while(!q.empty()){
			int x=q.front();q.pop();
			in[x]=false;
			for(int i=head[x];~i;i=nxt[i]){
				if(cap[i]&&dist[to[i]]>dist[x]+cost[i]){
					dist[to[i]]=dist[x]+cost[i];
					if(!in[to[i]])in[to[i]]=true,q.push(to[i]);
				}
			}
		}
		rep(i,V)if(i!=T)dist[i]=dist[T]-dist[i];
		dist[T]=0;
	}
	bool modify(){
		ll d=Inf;
		rep(i,V)if(vis[i]){
			for(int j=head[i];~j;j=nxt[j]){
				if(cap[j]&&!vis[to[j]])d=min(d,dist[to[j]]+cost[j]-dist[i]);
			}
		}
		if(d==Inf)return false;
		rep(i,V)if(vis[i])dist[i]+=d;
		return true; 
	}
	int dfs(int x,int f){
		vis[x]=true;
		if(x==T){
			ansc+=dist[S]*f;
			ansf+=f;
			return f;
		}
		int gf=0;
		for(int i=head[x];~i;i=nxt[i]){
			if(!vis[to[i]]&&cap[i]&&dist[to[i]]+cost[i]==dist[x]){
				int d=dfs(to[i],min(cap[i],f-gf));
				cap[i]-=d;
				cap[i^1]+=d;
				gf+=d;
				if(gf==f)break;
			}
		}
		return gf;
	}
	pair<int,ll>work(){
		ansc=ansf=0;
		spfa();
		for(;;){
			for(;;){
				rep(i,V)vis[i]=false;
				int d=dfs(S,INF);
				if(!d)break;
			}
			if(!modify())break;
		}
		return mp(ansf,ansc);
	}
}

ll calc(int f){
	Flow::init();
	Flow::S=402;Flow::T=403;Flow::V=404;
	rep(i,102)lim_mnx[i]=lim_mny[i]=0,lim_mxx[i]=lim_mxy[i]=n;
	rep(i,m){
		if(op[i]=='L')lim_mxx[a[i]]=min(lim_mxx[a[i]],b[i]);
		else if(op[i]=='R')lim_mnx[a[i]-1]=max(lim_mnx[a[i]-1],f-b[i]);
		else if(op[i]=='D')lim_mxy[a[i]]=min(lim_mxy[a[i]],b[i]);
		else lim_mny[a[i]-1]=max(lim_mny[a[i]-1],f-b[i]);
	}
	for(int i=100;i>=1;i--){
		lim_mxx[i]=min(lim_mxx[i],lim_mxx[i+1]);
		lim_mxy[i]=min(lim_mxy[i],lim_mxy[i+1]);
	}
	REP(i,100){
		lim_mnx[i]=max(lim_mnx[i],lim_mnx[i-1]);
		lim_mny[i]=max(lim_mny[i],lim_mny[i-1]);
	}
	int tot=0;
	REP(i,100){
		if(lim_mnx[i]>lim_mxx[i])return 0;
		if(lim_mny[i]>lim_mxy[i])return 0;
		int cur=lim_mnx[i]-lim_mnx[i-1];
		if(cur>0)Flow::addedge(Flow::S,i,cur,0),tot+=cur;
		else if(cur<0)Flow::addedge(i,Flow::T,-cur,0);
		if(i==100)Flow::addedge(0,i,lim_mxx[i]-lim_mnx[i],0);
		else Flow::addedge(i+1,i,lim_mxx[i]-lim_mnx[i],0);
		Flow::addedge(i,i+100,n,0); 
		cur=lim_mny[i-1]-lim_mny[i];
		if(cur>0)Flow::addedge(Flow::S,i+300,cur,0),tot+=cur;
		else if(cur<0)Flow::addedge(i+300,Flow::T,-cur,0);
		if(i==100)Flow::addedge(i+300,401,lim_mxy[i]-lim_mny[i],0);
		else Flow::addedge(i+300,i+300+1,lim_mxy[i]-lim_mny[i],0);
		Flow::addedge(i+200,i+300,n,0); 
	}
	if(lim_mnx[100])Flow::addedge(0,Flow::T,lim_mnx[100],0);
	if(lim_mny[100]){
		tot+=lim_mny[100];
		Flow::addedge(Flow::S,401,lim_mny[100],0);
	}
	rep(i,n)Flow::addedge(x[i]+100,y[i]+200,1,-v[i]);
	Flow::addedge(Flow::S,0,f,0);
	Flow::addedge(401,Flow::T,f,0);
	pair<int,ll>ans=Flow::work();
	if(ans.fst!=f+tot)return 0;
	return -ans.snd;
}

int main(){
	scanf("%d",&n);
	rep(i,n)scanf("%d%d%lld",&x[i],&y[i],&v[i]);
	scanf("%d",&m);
	rep(i,m){
		scanf("%s%d%d",s,&a[i],&b[i]);
		op[i]=s[0];
	}
	ll ans=0;
	REP(i,n)ans=max(ans,calc(i));
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 8576