//第8回シンデレラガール総選挙は是非本田未央ちゃんに投票をお願いします！
//ファンのことも他のアイドルの子たちのことも本当に大事にしてて、今まで周りに色んなものを与えてくれました。
//今度は私たちが未央ちゃんにお返しをする番です。みんなでガラスの靴を履かせてあげましょう！
// #本田未央を一番星に #本田未央を令和のシンデレラガールに #第8回シンデレラガール総選挙
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
namespace MCF {
	#define MAXN 10050
	#define MAXM 500000
	#define wint int
	#define cint lint
	const wint wEPS = 0;
	const wint wINF = 1001001001;
	const cint cEPS = 0;
	const cint cINF = 123456789012345678LL;
	int n, m, ptr[MAXN], next[MAXM], zu[MAXM];
	wint capa[MAXM], tof;
	cint cost[MAXM], toc, d[MAXN], pot[MAXN];
	int vis[MAXN], pree[MAXN];
	void init(int _n) {
		n = _n; m = 0; memset(ptr, ~0, n * 4);
	}
	void ae(int u, int v, wint w, cint c) {
		next[m] = ptr[u]; ptr[u] = m; zu[m] = v; capa[m] = w; cost[m] = +c; ++m;
		next[m] = ptr[v]; ptr[v] = m; zu[m] = u; capa[m] = 0; cost[m] = -c; ++m;
	}
	bool solve(int src, int ink, wint flo = wINF) {
		int i, u, v;
		wint f;
		cint c, cc;
		memset(pot, 0, n * sizeof(cint));
		
		for (bool cont = 1; cont ;) {
			cont = 0;
			for (u = 0; u < n; ++u) for (i = ptr[u]; ~i; i = next[i]) if (capa[i] > wEPS) {
				if (pot[zu[i]] > pot[u] + cost[i] + cEPS) {
					pot[zu[i]] = pot[u] + cost[i]; cont = 1;
				}
			}
		}
		
		for (toc = 0, tof = 0; tof + wEPS < flo; ) {
			typedef pair<cint, int> node;
			priority_queue<node, vector<node>, greater<node> > q;
			for (u = 0; u < n; ++u) { d[u] = cINF; vis[u] = 0; }
			for (q.push(mp(d[src] = 0, src)); !q.empty(); ) {
				c = q.top().first; u = q.top().second; q.pop();
				if (vis[u]++) continue;
				for (i = ptr[u]; ~i; i = next[i]) if (capa[i] > wEPS) {
					cc = c + cost[i] + pot[u] - pot[v = zu[i]];
					if (d[v] > cc) { q.push(mp(d[v] = cc, v)); pree[v] = i; }
				}
			}
			if (!vis[ink]) return 0;
			f = flo - tof;
			for (v = ink; v != src; v = zu[i ^ 1]) { i = pree[v]; f = min(f, capa[i]); }
			for (v = ink; v != src; v = zu[i ^ 1]) { i = pree[v]; capa[i] -= f; capa[i ^ 1] += f; }
			tof += f;
			toc += f * (d[ink] - pot[src] + pot[ink]);
			for (u = 0; u < n; ++u) pot[u] += d[u];
		}
		return 1;
	}
}
vector<pint> L,R,U,D,V;
int x[84],y[84];lint v[84];
lint inf=1234567890123456LL;
int lx[84],ly[84],hx[84],hy[84];
int main()
{
	int n,m,a,b;char c;
	cin>>n;
	rep(i,n) cin>>x[i]>>y[i]>>v[i];
	cin>>m;rep(i,m){
		cin>>c>>a>>b;
		if(c=='L') L.pb(mp(a,b));
		if(c=='R') R.pb(mp(a,b));
		if(c=='D') D.pb(mp(a,b));
		if(c=='U') U.pb(mp(a,b));
	}
	/*if(L.size()>0){
		sort(All(L));reverse(All(L));
		V.pb(L[0]);
		REP(i,1,L.size()){
			if(L[i].se<L[i-1].se) V.pb(L[i]);
		}
		L=V;V.clear();
	}
	if(R.size()>0){
		sort(All(R));//reverse(All(L));
		V.pb(R[0]);
		REP(i,1,L.size()){
			if(R[i].se<R[i-1].se) V.pb(R[i]);
		}
		R=V;V.clear();
	}
	if(D.size()>0){
		sort(All(D));reverse(All(D));
		V.pb(D[0]);
		REP(i,1,D.size()){
			if(D[i].se<D[i-1].se) V.pb(D[i]);
		}
		D=V;V.clear();
	}
	if(U.size()>0){
		sort(All(U));//reverse(All(U));
		V.pb(U[0]);
		REP(i,1,U.size()){
			if(U[i].se<U[i-1].se) V.pb(U[i]);
		}
		U=V;V.clear();
	}*/
	lint out=0;
	rep(i,n+1){
		rep(j,i+1) lx[j]=ly[j]=0,hx[j]=hy[j]=100;
		rep(j,L.size()) REP(k,L[j].se,i) lx[k]=max(lx[k],L[j].fi+1);
		//if(i==4) cout<<L.size()<<' '<<L[0].se<<' '<<L[0].fi<<' '<<lx[1]<<endl;
		rep(j,R.size()) REP(k,R[j].se,i) hx[i-1-k]=min(hx[i-1-k],R[j].fi-1);
		rep(j,D.size()) REP(k,D[j].se,i) ly[k]=max(ly[k],D[j].fi+1);
		rep(j,U.size()) REP(k,U[j].se,i) hy[i-1-k]=min(hy[i-1-k],U[j].fi-1);
		//cout<<i<<endl;rep(j,i) cout<<lx[j]<<' '<<hx[j]<<' '<<ly[j]<<' '<<hy[j]<<endl;
		int S=n*2+i*2,T=S+1;
		MCF::init(T+1);
		rep(j,i) MCF::ae(S,j,1,0),MCF::ae(i+j,T,1,0);
		rep(j,n){
			MCF::ae(i*2+j,i*2+n+j,1,inf-v[j]);
			rep(k,i){
				if(lx[k]<=x[j] && x[j]<=hx[k]) MCF::ae(k,i*2+j,1,0);
				if(ly[k]<=y[j] && y[j]<=hy[k]) MCF::ae(i*2+n+j,i+k,1,0);
			}
		}
		MCF::solve(S,T);
		//cout<<i<<' '<<MCF::tof<<endl;
		if(i==MCF::tof){
			out=max(out,inf*i-MCF::toc);
			//cout<<i<<' '<<inf*i-MCF::toc<<endl;
		}
	}
	cout<<out<<endl;
}


Measured memory_bytes: 4608