#include<bits/stdc++.h>
using namespace std;
namespace io{
    const int l=1<<20;
    char buf[l],*s,*t,c;
    inline void gc(){
        if(s==t){
            t=(s=buf)+fread(buf,1,l,stdin);
            c=s==t?EOF:*s++;
        }else c=*s++;
    }
    template<class IT>inline void gi(IT &x){
        x=0;gc();while(c<'0'||c>'9')gc();
        while('0'<=c&&c<='9'){x=(x<<1)+(x<<3)+(c^48);gc();}
    }
    char buf0[20];int a;
    template<class IT>inline void pi(IT x){
        if(x<0){putchar('-');x=-x;}
        do buf0[++a]=x%10+48;while(x/=10);
        while(a)putchar(buf0[a--]);
        putchar('\n');
    }
};
using io::gi;
using io::pi;
typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<int,ll > pil;
typedef pair<ll ,int> pli;
typedef pair<ll ,ll > pll;
typedef vector<int> vi;
typedef vector<ll > vl;
#define pque priority_queue
#define rep(i,l,r) for(i=(l);i<=(r);++i)
#define per(i,l,r) for(i=(l);i>=(r);--i)
#define REP(i,l,r) for(i=(l);i< (r);++i)
#define PER(i,l,r) for(i=(l);i> (r);--i)
#define mp make_pair
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define fi first
#define se second
template<class IT>inline void cmax(IT &a,IT b){if(a<b)a=b;}
template<class IT>inline void cmin(IT &a,IT b){if(b<a)a=b;}
const int N=85,V=N<<2;const ll inf=-1000000000000000000ll;
struct edge{
	int u,w1;ll w2;int n;
	inline edge(){}
	inline edge(int u,int w1,ll w2,int n):u(u),w1(w1),w2(w2),n(n){}
}e[N*V];int f[V],tot;
inline void add(int v,int u,ll w2=0ll){
	//printf("%d %d %lld\n",v,u,w2);
	e[tot]=edge(u,1, w2,f[v]);f[v]=(tot++);
	e[tot]=edge(v,0,-w2,f[u]);f[u]=(tot++);
}
int q[V],in[V],p[V],pe[V];ll d[V];
inline ll spfa(int S){
	int l=1,r=1,v,i,u;ll w;
	q[1]=S;
	REP(i,1,S)in[i]=0;
	REP(i,1,S)d[i]=inf;d[S]=0ll;//printf("d5=%lld\n",d[5]);
	while(l<=r){
		in[v=q[(l++)%V]]=0;
		for(i=f[v];~i;i=e[i].n)if(e[i].w1){
			u=e[i].u;
			//printf("v=%d -> u=%d dv=%lld du=%lld w=%lld\n",v,u,d[v],d[u],e[i].w2);
			if((w=d[v]+e[i].w2)>d[u]){
				//printf("v=%d -> u=%d in=%d\n",v,u,in[u]);
				d[u]=w;
				p[u]=v;
				pe[u]=i;
				if(!in[u]){
					in[u]=1;
					q[(++r)%V]=u;
				}
			}
		}
	}
	return d[S-1];
}
struct jewel{
	int x,y;ll z;
}J[N];
struct clue{
	int a,b;char c;
}C[V];
int lx[N],rx[N],ly[N],ry[N];
int main(){
    //freopen("a.in","r",stdin);
    //freopen("a.out","w",stdout);
    int n,m,i,j,k,v,u,ans1;ll ans2,ans=0ll,f2;
	char str[2];
    scanf("%d",&n);
    rep(i,1,n)scanf("%d%d%lld",&J[i].x,&J[i].y,&J[i].z);
	scanf("%d",&m);
	rep(i,1,m){scanf("%s%d%d",str,&C[i].a,&C[i].b);C[i].c=str[0];}
	rep(k,1,n){
		rep(i,1,k)lx[i]=1  ;
		rep(i,1,k)rx[i]=100;
		rep(i,1,k)ly[i]=1  ;
		rep(i,1,k)ry[i]=100;
		rep(i,1,m)if(C[i].b<k){
			switch(C[i].c){
				case 'L':cmax(lx[  C[i].b+1],C[i].a+1);break;
				case 'R':cmin(rx[k-C[i].b  ],C[i].a-1);break;
				case 'D':cmax(ly[  C[i].b+1],C[i].a+1);break;
				case 'U':cmin(ry[k-C[i].b  ],C[i].a-1);break;
			}
		}
		rep(i,2,k)cmax(lx[i  ],lx[i-1]);
		rep(i,2,k)cmax(ly[i  ],ly[i-1]);
		per(i,k,2)cmin(rx[i-1],rx[i  ]);
		per(i,k,2)cmin(ry[i-1],ry[i  ]);
		//rep(i,1,k)printf("[%d,%d] [%d,%d]\n",lx[i],rx[i],ly[i],ry[i]);
		memset(f,-1,sizeof(f));tot=0;
		v=(u=((n+k)<<1|1))+1;
		rep(i,1,k)add(v,(n<<1)+i  );
		rep(i,1,k)add(k+(n<<1)+i,u);
		rep(i,1,n)add(i,i+n,J[i].z);
		rep(i,1,k)rep(j,1,n){
			if(lx[i]<=J[j].x&&J[j].x<=rx[i])add(    (n<<1)+i,j);
			if(ly[i]<=J[j].y&&J[j].y<=ry[i])add(j+n,(n<<1)+i+k);
		}
		ans1=0;ans2=0ll;
		while((f2=spfa(v))!=inf){
			//printf("f2=%lld\n",f2);
			++ans1;
			ans2+=f2;
			for(i=u;i!=v;i=p[i]){
				//printf("(%d,%d) ",i,pe[i]);
				e[pe[i]  ].w1=0;
				e[pe[i]^1].w1=1;
			}
			//puts("");
		}
		//printf("k=%d ans1=%d ans2=%lld\n",k,ans1,ans2);
		if(ans1!=k)break;cmax(ans,ans2);
	}
	printf("%lld",ans);
    return 0;
}

Measured memory_bytes: 640