#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<bitset>
#include<set>
#define N (100010)
#define P ()
#define M ()
#define inf (0x7f7f7f7f)
#define rg register int
#define Label puts("NAIVE")
#define spa print(' ')
#define ent print('\n')
#define rand() (((rand())<<(15))^(rand()))
#define file(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)
typedef long double ld;
typedef long long LL;
typedef unsigned long long ull;
using namespace std;
namespace fastIO1{
	inline char read(){
		static const int IN_LEN=1000000;
		static char buf[IN_LEN],*s,*t;
		return (s==t?t=(s=buf)+fread(buf,1,IN_LEN,stdin),(s==t?-1:*s++):*s++);
	}
	template<class T>
	inline void read(T &x){
		static bool iosig;
		static char c;
		for(iosig=false,c=read();!isdigit(c);c=read()){
			if(c=='-')iosig=true;
			if(c==-1)return;
		}
		for(x=0;isdigit(c);c=read())x=((x+(x<<2))<<1)+(c^'0');
		if(iosig)x=-x;
	}
	inline char readc(char &c){
		for(c=read();!isalpha(c)&&!isdigit(c);c=read())
		if(c==-1)return 0;
	}
	const int OUT_LEN = 10000000;
	char obuf[OUT_LEN],*ooh=obuf;
	inline void print(char c){
		if(ooh==obuf+OUT_LEN)fwrite(obuf,1,OUT_LEN,stdout),ooh=obuf;
		*ooh++=c;
	}
	template<class T>
	inline void print(T x){
		static int buf[30],cnt;
		if(x==0)print('0');
		else{
			if(x<0)print('-'),x=-x;
			for(cnt=0;x;x/=10)buf[++cnt]=x%10+48;
			while(cnt)print((char)buf[cnt--]);
		}
	}
	inline void flush(){fwrite(obuf,1,ooh-obuf,stdout);}
}
namespace fastIO2{
	template<class T>
	inline void read(T &x){
		static bool iosig;
		static char c;
		for(iosig=false,c=getchar();!isdigit(c);c=getchar()){
			if(c=='-')iosig=true;
			if(c==-1)return;
		}
		for(x=0;isdigit(c);c=getchar())x=((x+(x<<2))<<1)+(c^'0');
		if(iosig)x=-x;
	}
}
using namespace fastIO1;
struct limits{int l,op,x;}q[N];
struct points{int x,y;LL w;}a[N];
int n,m,E=1,S,T,V,fl,lx[N],rx[N],ly[N],ry[N];
int fi[N],ne[N],b[N],cap[N],pre[N],prv[N];
bool vis[N]; LL ans,mx,ot,c[N],dis[N];
void add(int x,int y,int cp,LL cost){
//	printf("%d--%lld-->%d\n",x,cost,y);
	ne[++E]=fi[x],fi[x]=E,b[E]=y;
	cap[E]=cp,c[E]=cost;
	ne[++E]=fi[y],fi[y]=E,b[E]=x;
	cap[E]=0,c[E]=-cost;
}
void mcmf(int S,int T,int flow,int cnt){
	while(flow){
		for(int i=1;i<=V;i++)dis[i]=1e18,vis[i]=0;
		dis[S]=0; queue<int> Q; Q.push(S),vis[S]=1;
		while(!Q.empty()){
			int u=Q.front();Q.pop(),vis[u]=0;
			if(dis[u]==1e18)continue;
			for(int i=fi[u];i;i=ne[i]){
				int v=b[i];
				if(cap[i]>0&&dis[u]+c[i]<dis[v]){
                    dis[v]=dis[u]+c[i];
                    prv[v]=u,pre[v]=i;
                    if(!vis[v])Q.push(v),vis[v]=1;
                }
			}
		}
		if(dis[T]==1e18)break;
		int w=flow;
		for(int i=T;i!=S;i=prv[i])
		w=min(w,cap[pre[i]]);
		flow-=w,mx+=dis[T],fl+=w;
		for(int i=T;i!=S;i=prv[i]){
			int e=pre[i];
			cap[e]-=w,cap[e^1]+=w;
		}
	}
}
void solve(int cnt){
	memset(fi,0,n*32),E=1,fl=0;
	memset(rx,inf,(n+3)<<2);
	memset(lx,0,(n+3)<<2);
	memset(ry,inf,(n+3)<<2);
	memset(ly,0,(n+3)<<2);
//	cout<<cnt<<endl;
	for(int j=1;j<=m;j++){
		int t=(q[j].op&1)?q[j].x+1:cnt-q[j].x;
//		cout<<j<<" "<<t<<endl;
		if(t>cnt||t<=0)continue;
		
		if(q[j].op==1)lx[t]=max(lx[t],q[j].l+1);
		else if(q[j].op==2)rx[t]=min(rx[t],q[j].l-1);
		else if(q[j].op==3)ly[t]=max(ly[t],q[j].l+1);
		else ry[t]=min(ry[t],q[j].l-1);
	}
	for(int i=2;i<=cnt;i++)lx[i]=max(lx[i-1],lx[i]),ly[i]=max(ly[i-1],ly[i]);
	for(int i=cnt;i;i--)rx[i]=min(rx[i+1],rx[i]),ry[i]=min(ry[i+1],ry[i]);
//	for(int j=1;j<=cnt;j++)cout<<lx[j]<<" "<<rx[j]<<endl;
//	for(int j=1;j<=cnt;j++)cout<<ly[j]<<" "<<ry[j]<<endl;
//	for(int j=1;j<=cnt;j++)cout<
	S=2*(n+cnt)+1,T=S+1,V=T;
	for(int i=1;i<=n;i++)add(i,i+n,1,-a[i].w);
	for(int i=1;i<=cnt;i++){
		if(lx[i]>rx[i]||ly[i]>ry[i])return;
		for(int j=1;j<=n;j++)
		if(lx[i]<=a[j].x&&a[j].x<=rx[i])
		add(i+2*n,j,1,0);
		for(int j=1;j<=n;j++)
		if(ly[i]<=a[j].y&&a[j].y<=ry[i])
		add(j+n,i+2*n+cnt,1,0);
		add(S,i+2*n,1,0),add(i+2*n+cnt,T,1,0);
	}
	mx=0,mcmf(S,T,inf,cnt),ot=max(ot,-mx);
//	cout<<cnt<<" "<<fl<<" "<<mx<<endl;
//	cout<<"ans="<<-ans<<endl;
//	puts("--------------");
}
int main(){
	read(n);
	for(int i=1;i<=n;i++)read(a[i].x),read(a[i].y),read(a[i].w); read(m);
	for(int i=1;i<=m;i++){
		char ch; readc(ch),read(q[i].l),read(q[i].x);
		q[i].op=(ch=='L')?1:ch=='R'?2:ch=='D'?3:4;
	}
	for(int i=1;i<=n;i++)solve(i); cout<<ot;
}

Measured memory_bytes: 8576