#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<queue>
#include<cmath>
#include<cstdlib>
#define LL long long
#define LD long double
using namespace std;
const int NN=90;
const int MM=1000 +117;
int read(){
	int fl=1,x;char c;
	for(c=getchar();(c<'0'||c>'9')&&c!='-';c=getchar());
	if(c=='-'){fl=-1;c=getchar();}
	for(x=0;c>='0'&&c<='9';c=getchar())
		x=(x<<3)+(x<<1)+c-'0';
	return x*fl;
}
void open(){
	freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
}
void close(){
	fclose(stdin);
	fclose(stdout);
}


int m,n;
int pos[NN][2]={};
LL v[NN]={};
struct node{
	int l,r;
}x[NN],y[NN]={};
int q[MM][3]={};
int f[300]={};
int p[4*NN]={};
int ecnt=0;
int pcnt=0;
int st,fin;
int maxf;
LL minc;
struct edge{
	int to,xt,rem;
	LL ct;
}e[6*NN*NN]={};
void ADD(int a,int b,int rem,LL ct){
	++ecnt;
	e[ecnt].to=b;
	e[ecnt].xt=p[a];
	e[ecnt].rem=rem;
	e[ecnt].ct=ct;
	p[a]=ecnt;
}
void add(int a,int b,int rem,LL ct){
	//cerr<<"from "<<a<<" to "<<b<<" cap:"<<rem<<" cost:"<<ct<<endl;
	ADD(a,b,rem,ct);
	ADD(b,a,0,-ct);
}
LL sp[4*NN]={};
int pre[4*NN]={};
bool inq[4*NN]={};
queue<int> qu;
bool spfa(){
	for(int i=1;i<=pcnt;++i){
		sp[i]=1e18;
	}
	sp[st]=0;
	qu.push(st);
	while(!qu.empty()){
		int x=qu.front();
		qu.pop();
		inq[x]=0;
		for(int pos=p[x];pos;pos=e[pos].xt){
			int cur=e[pos].to;
			if(e[pos].rem&&e[pos].ct+sp[x]<sp[cur]){
				sp[cur]=sp[x]+e[pos].ct;
				pre[cur]=pos;
				if(!inq[cur]){
					qu.push(cur);
					inq[cur]=1;
				}
			}
		}
	}
	return sp[fin]!=1e18;
}
void getf(){
	maxf=0;
	minc=0;
	while(spfa()){
		maxf+=1;
		minc+=sp[fin];
		int pos=fin;
		while(pos!=st){
			int id=pre[pos];
			e[id].rem-=1;
			e[id^1].rem+=1;
			pos=e[id^1].to;
		}
	}
}
LL solve(int all){
	for(int i=1;i<=all;++i){
		x[i].l=0;
		x[i].r=1e9;
		y[i].l=0;
		y[i].r=1e9;
	}
	for(int i=1;i<=m;++i){
		int a=q[i][1];
		int b=q[i][2];
		switch(q[i][0]){
			case 0:
			x[b+1].l=max(x[b+1].l,a+1);
			break;
			case 1:
			if(all>b)x[all-b].r=min(x[all-b].r,a);
			break;
			case 2:
			y[b+1].l=max(y[b+1].l,a+1);
			break;
			case 3:
			if(all>b)y[all-b].r=min(y[all-b].r,a);
			break;
		}
	}
	for(int i=2;i<=all;++i){
		x[i].l=max(x[i-1].l,x[i].l);
		y[i].l=max(y[i-1].l,y[i].l);
	}
	for(int i=all-1;i>=1;--i){
		x[i].r=min(x[i+1].r,x[i].r);
		y[i].r=min(y[i+1].r,y[i].r);
	}
	for(int i=1;i<=all;++i){
		if(x[i].l>x[i].r||y[i].l>y[i].r)return -1;
	}
	st=2*n+2*all+1;
	fin=st+1;
	ecnt=1;
	pcnt=fin;
	for(int i=1;i<=pcnt;++i)p[i]=0;
	for(int i=1;i<=n;++i){
		add(i,n+i,1,-v[i]);
	}
	for(int i=1;i<=all;++i){
		add(st,2*n+i,1,0);
		add(2*n+all+i,fin,1,0);
		for(int j=1;j<=n;++j){
			if(x[i].l<=pos[j][0]&&pos[j][0]<=x[i].r){
				add(2*n+i,j,1,0);
			}
			if(y[i].l<=pos[j][1]&&pos[j][1]<=y[i].r){
				add(n+j,2*n+all+i,1,0);
			}
		}
	}
	getf();
	if(maxf==all)return -minc;
	else return -1;
}
int lix[NN]={};
int liy[NN]={};
char getc(){
	char c=getchar();
	while(c==' '||c=='\n'||c=='\r')c=getchar();
	return c;
}
int main(){
	//open();
	n=read();
	for(int i=1;i<=n;++i){
		lix[i]=pos[i][0]=read();
		liy[i]=pos[i][1]=read();
		scanf("%lld",&v[i]);
	}
	sort(lix+1,lix+1+n);
	sort(liy+1,liy+1+n);
	f['L']=0;
	f['R']=1;
	f['D']=2;
	f['U']=3;
	m=read();
	for(int i=1;i<=m;++i){
		q[i][0]=f[getc()];
		q[i][1]=read()-(q[i][0]&1);
		q[i][2]=read();
		/*if(q[i][0]&2){
			q[i][1]=upper_bound(liy+1,liy+1+n,q[i][1])-liy-1;
		}
		else{
			q[i][1]=upper_bound(lix+1,lix+1+n,q[i][1])-lix-1;
		}*/
	}
	LL ans=0;
	for(int i=1;i<=n;++i){
		LL tp=solve(i);
		//cerr<<tp<<endl;
		ans=max(ans,tp);
	}
	printf("%lld\n",ans);
	close();
	return 0;
}

Measured memory_bytes: 640