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

#define pb push_back
#define mk make_pair
#define lob lower_bound
#define upb upper_bound
#define fst first
#define scd second

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

inline int read(){
	int f=1,x=0;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
inline ll readll(){
	ll f=1,x=0;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

int n,m,x[85],y[85],limxl[105],limxr[105],limyl[105],limyr[105],xL[85],xR[85],yL[85],yR[85];
ll val[85];
const ll INF=1e18;
struct EDGE{int nxt,to,w;ll c;}edge[6000000];
int head[5005],tot,nodecnt;
inline void add_edge(int u,int v,int w,ll c){
	edge[++tot].nxt=head[u],edge[tot].to=v,edge[tot].w=w,edge[tot].c=c,head[u]=tot;
	edge[++tot].nxt=head[v],edge[tot].to=u,edge[tot].w=0,edge[tot].c=-c,head[v]=tot;
}
int pre[5005];
bool inq[5005];
ll dis[5005];
bool spfa(int s,int t){
	for(int i=1;i<=nodecnt;++i)inq[i]=0,dis[i]=-INF,pre[i]=0;
	queue<int>q;q.push(s);dis[s]=0;
	while(!q.empty()){
		int u=q.front();q.pop();inq[u]=0;
		for(int i=head[u];i;i=edge[i].nxt){
			int v=edge[i].to;
			if(edge[i].w&&dis[v]<dis[u]+edge[i].c){
				dis[v]=dis[u]+edge[i].c;
				pre[v]=i;
				if(!inq[v]){
					inq[v]=1;
					q.push(v);
				}
			}
		}
	}
	return dis[t]!=-INF;
}
ll solve(int num){
	for(int i=1;i<=num;++i)xL[i]=yL[i]=1,xR[i]=yR[i]=100;	
	for(int i=1;i<=100;++i){
		if(limxl[i]<num)xL[limxl[i]+1]=max(xL[limxl[i]+1],i+1);
		if(limxr[i]<num)xR[num-limxr[i]]=min(xR[num-limxr[i]],i-1);
		if(limyl[i]<num)yL[limyl[i]+1]=max(yL[limyl[i]+1],i+1);
		if(limyr[i]<num)yR[num-limyr[i]]=min(yR[num-limyr[i]],i-1);
	}
//	cout<<"--------- solveing "<<num<<" --------"<<endl;
	for(int i=num-1;i>=1;--i)xR[i]=min(xR[i],xR[i+1]),yR[i]=min(yR[i],yR[i+1]);
	for(int i=2;i<=num;++i)xL[i]=max(xL[i],xL[i-1]),yL[i]=max(yL[i],yL[i-1]);
//	for(int i=1;i<=num;++i){
//		cout<<i<<" "<<xL[i]<<" "<<xR[i]<<endl;
//		cout<<i<<" "<<yL[i]<<" "<<yR[i]<<endl;
//	}
	for(int i=1;i<=num;++i)if(xL[i]>xR[i]||yL[i]>yR[i])return -1;
	tot=1;for(int i=1;i<=nodecnt;++i)head[i]=0;
	for(int i=1;i<=n;++i)add_edge(i,n+i,1,val[i]);
	for(int i=1;i<=num;++i){
		for(int j=1;j<=n;++j){
			if(xL[i]<=x[j]&&xR[i]>=x[j])add_edge(n*2+i,j,1,0);
			if(yL[i]<=y[j]&&yR[i]>=y[j])add_edge(n+j,n*2+num+i,1,0);
		}
	}
	int s=n*2+num*2+1,t=s+1;nodecnt=t;
	for(int i=1;i<=num;++i)add_edge(s,n*2+i,1,0),add_edge(n*2+num+i,t,1,0);
	ll ans=0;
	while(spfa(s,t)){
		int fl=1e9;
		for(int i=pre[t];i;i=pre[edge[i^1].to]){
			fl=min(fl,edge[i].w);
		}
		for(int i=pre[t];i;i=pre[edge[i^1].to]){
			ans+=edge[i].c*fl;
			edge[i].w-=fl;
			edge[i^1].w+=fl;
		}
	}
//	cout<<"** "<<num<<" "<<ans<<endl;
	return ans;
}
int main() {
	scanf("%d",&n);
	for(int i=1;i<=n;++i)scanf("%d%d%lld",x+i,y+i,val+i);
	for(int i=1;i<=100;++i)limxl[i]=n,limxr[i]=n,limyl[i]=n,limyr[i]=n;
	scanf("%d",&m);
	for(int i=1;i<=m;++i){
		char s[5];int a,b;scanf("%s%d%d",s,&a,&b);
		if(s[0]=='L')limxl[a]=min(limxl[a],b);
		else if(s[0]=='R')limxr[a]=min(limxr[a],b);
		else if(s[0]=='D')limyl[a]=min(limyl[a],b);
		else if(s[0]=='U')limyr[a]=min(limyr[a],b);else assert(0);
	}
	ll ans=0;
	for(int i=1;i<=n;++i)ans=max(ans,solve(i));
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 768