#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN=500;
const int MAXGN=4*MAXN+2;
const int MAXGM=5*MAXN;

typedef struct MCMF {
	int n,m;
	vector<int> ghead,gnxt,gto,gcap; vector<ll> gcost;

	vector<ll> d; vector<int> bck; vector<ll> pot;

	//int ghead[MAXGN],gnxt[2*MAXGM],gto[2*MAXGM],gcap[2*MAXGM],gcost[2*MAXGM];
	//int d[MAXGN]; int bck[MAXGN];
	//int pot[MAXGN];

	void init(int _n) { n=_n,m=0; ghead=vector<int>(n,-1); gnxt.clear(),gto.clear(),gcap.clear(),gcost.clear(); d=vector<ll>(n); bck=vector<int>(n); pot=vector<ll>(n,0); }
	void addedge(int a,int b,int c,ll d) {
		gnxt.PB(ghead[a]); ghead[a]=m; gto.PB(b); gcap.PB(c); gcost.PB(+d); ++m;
		gnxt.PB(ghead[b]); ghead[b]=m; gto.PB(a); gcap.PB(0); gcost.PB(-d); ++m;
		//printf("adding edge %d-%d with cap %d and cost %lld\n",a,b,c,d);
	}
	pair<int,ll> solve(int s,int t) {
		//REP(i,n) { printf("%d:",i); for(int x=ghead[i];x!=-1;x=gnxt[x]) printf(" %d",gto[x]); puts(""); }

		REP(i,n) d[i]=LLONG_MAX,bck[i]=-1; d[s]=0,bck[s]=-2;
		while(true) {
			bool change=false;
			REP(at,n) if(d[at]!=LLONG_MAX) for(int x=ghead[at];x!=-1;x=gnxt[x]) if(gcap[x]>0) {
				int to=gto[x]; if(d[at]+gcost[x]>=d[to]) continue;
				d[to]=d[at]+gcost[x]; bck[to]=x^1; change=true;
			}
			if(!change) break;
		}
		if(d[t]==LLONG_MAX) return MP(0,0);
		REP(i,n) pot[i]=d[i];


		pair<int,ll> ret=MP(0,0LL);
		while(true) {
			REP(i,n) d[i]=LLONG_MAX,bck[i]=-1; d[s]=0,bck[s]=-2;
			priority_queue<pair<ll,int> > q; q.push(MP(-d[s],s));
			while(!q.empty()) {
				ll cost=-q.top().first; int at=q.top().second; q.pop();
				if(cost>d[at]) continue;
				for(int x=ghead[at];x!=-1;x=gnxt[x]) if(gcap[x]>0) {
					int to=gto[x]; ll rcost=gcost[x]-pot[at]+pot[to]; if(d[at]+rcost>=d[to]) continue;
					d[to]=d[at]+rcost; bck[to]=x^1; q.push(MP(-d[to],to));
				}
			}
			if(d[t]==LLONG_MAX) break;
			//printf("%d\n",d[t]-pot[t]);
			++ret.first,ret.second+=d[t]-pot[t];
			REP(i,n) if(d[i]!=LLONG_MAX) pot[i]-=d[i];

			for(int at=t;at!=s;at=gto[bck[at]]) {
				//printf("%d ",at);
				++gcap[bck[at]]; --gcap[bck[at]^1];
			}
			//printf("%d ",s);
			//puts("");
		}
		return ret;
	}
} MCMF;
MCMF g;


const int MAXP=80;
const int MAXCOND=320;
struct P { int x,y; ll val; };
struct Cond { int pos,lim; };
bool operator<(const Cond &a,const Cond &b) { if(a.pos!=b.pos) return a.pos<b.pos; return a.lim>b.lim; }

int np;
P p[MAXP];
int ncond;
vector<Cond> lcond,rcond,ucond,dcond;
Cond cond[MAXCOND];

vector<int> lx,hx,ly,hy;

vector<int> calcbound(int want,vector<Cond> cond,bool inv) {
	if(inv) REPSZ(i,cond) cond[i].pos=-cond[i].pos;
	sort(cond.begin(),cond.end());
	int nsz=0; REPSZ(i,cond) { while(nsz>0&&cond[nsz-1].lim>=cond[i].lim) --nsz; cond[nsz++]=cond[i]; } cond.resize(nsz);
	vector<int> ret(want); int at=0; REPSZ(i,ret) { while(at<SZ(cond)&&cond[at].lim<=i) ++at; ret[i]=at==0?INT_MIN:cond[at-1].pos+1; }
	if(inv) { reverse(ret.begin(),ret.end()); REPSZ(i,ret) if(ret[i]==INT_MIN) ret[i]=INT_MAX; else ret[i]=-ret[i]; }
	return ret;
}

ll calc(int want) {
	int sid,tid; vector<int> xcondid(want),ycondid(want),lpid(np),rpid(np);
	int nid=0; sid=nid++; tid=nid++; REP(i,want) xcondid[i]=nid++; REP(i,want) ycondid[i]=nid++; REP(i,np) lpid[i]=nid++,rpid[i]=nid++;
	g.init(nid);
	REP(i,want) g.addedge(sid,xcondid[i],1,0);
	REP(i,want) REP(j,np) if(lx[i]<=p[j].x&&p[j].x<=hx[i]) g.addedge(xcondid[i],lpid[j],1,0);
	REP(j,np) g.addedge(lpid[j],rpid[j],1,-p[j].val);
	REP(j,np) REP(i,want) if(ly[i]<=p[j].y&&p[j].y<=hy[i]) g.addedge(rpid[j],ycondid[i],1,0);
	REP(i,want) g.addedge(ycondid[i],tid,1,0);
	return -g.solve(sid,tid).second;
}

ll solve() {
	ll ret=0;
	FORE(want,1,np) {
		lx=calcbound(want,lcond,false);
		hx=calcbound(want,rcond,true);
		ly=calcbound(want,dcond,false);
		hy=calcbound(want,ucond,true);
		bool ok=true; REP(i,want) if(lx[i]>hx[i]||ly[i]>hy[i]) ok=false; if(!ok) continue;
		//printf("want=%d\n",want);
		//printf("lx:"); REPSZ(i,lx) printf(" %d",lx[i]); puts("");
		//printf("hx:"); REPSZ(i,hx) printf(" %d",hx[i]); puts("");
		//printf("ly:"); REPSZ(i,ly) printf(" %d",ly[i]); puts("");
		//printf("hy:"); REPSZ(i,hy) printf(" %d",hy[i]); puts("");
		ll cur=calc(want);
		//printf("->%lld\n",cur);
		ret=max(ret,cur);
	}
	return ret;
}

void run() {
	scanf("%d",&np);
	REP(i,np) scanf("%d%d%lld",&p[i].x,&p[i].y,&p[i].val);
	scanf("%d",&ncond);
	lcond.clear(),rcond.clear(),ucond.clear(),dcond.clear(); REP(i,ncond) { char kind; scanf(" %c",&kind); Cond cond; scanf(" %d%d",&cond.pos,&cond.lim); if(kind=='L') lcond.PB(cond); else if(kind=='R') rcond.PB(cond); else if(kind=='D') dcond.PB(cond); else if(kind=='U') ucond.PB(cond); else assert(false); }
	printf("%lld\n",solve());
}


int main() {
	run();
	return 0;
}


Measured memory_bytes: 972