#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using uint = unsigned int;
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep1(i,n) for(int i=1;i<=int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define all(c) c.begin(),c.end()
#define si(x) int(x.size())
#define pb emplace_back
#define fs first
#define sc second
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
template<class T,class U> void chmax(T& x, U y){if(x<y) x=y;}
template<class T,class U> void chmin(T& x, U y){if(y<x) x=y;}
template<class T> void mkuni(V<T>& v){sort(all(v));v.erase(unique(all(v)),v.end());}
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
void dmpr(ostream& os){os<<endl;}
template<class T,class... Args>
void dmpr(ostream&os,const T&t,const Args&... args){
	os<<t<<" ~ ";
	dmpr(os,args...);
}
#define shows(...) cerr << "LINE" << __LINE__ << " : ";dmpr(cerr,##__VA_ARGS__)
#define dump(x) cerr << "LINE" << __LINE__ << " : " << #x << " = {";  \
	for(auto v: x) cerr << v << ","; cerr << "}" << endl;
#else
#define show(x) void(0)
#define dump(x) void(0)
#define shows(...) void(0)
#endif

struct MinCostFlow{
	using C = ll;		// capacity
	using D = ll;		// distance (cost)
	const D inf = 1e18;

	struct edge{
		int to;
		C cap;
		D dist;
		int rev;
		edge(int to_,C cap_, D dist_, int rev_):to(to_),cap(cap_),dist(dist_),rev(rev_){}
	};
	
	int N;
	VV<edge> G;
	V<D> h;
	V<D> dist;
	V<int> prevv,preve;
	MinCostFlow(int N_):N(N_){
		G.resize(N);
		h.resize(N);
		dist.resize(N);
		prevv.resize(N);
		preve.resize(N);
	}

	void add_edge(int from, int to, C cap, D dist){
//		cerr << "add edge: " << from " -> " << to << "(cap,dist) = " << cap << "," << dist << endl;
		edge e1(to,cap,dist,(int)G[to].size());
		edge e2(from,0,-dist,(int)G[from].size());
		G[from].push_back(e1);
		G[to].push_back(e2);
	}
	D min_cost_flow(int s, int t, C f){
		D res = 0;
		h = V<D>(N);
		while(f > 0){
			using P = pair<D,int>;
			priority_queue< P,vector<P>,greater<P> > que;
			dist = V<D>(N,inf);
			dist[s] = 0;
			que.push(P(0,s));
			while(!que.empty()){
				P p = que.top();
				que.pop();
				int v = p.second;
				if(dist[v] < p.first) continue;
				for(int i=0;i<(int)G[v].size();i++){
					edge &e = G[v][i];
					if(e.cap>0 && dist[e.to]>dist[v]+e.dist+h[v]-h[e.to]){
						dist[e.to]=dist[v]+e.dist+h[v]-h[e.to];
						prevv[e.to]=v;
						preve[e.to]=i;
						que.push(P(dist[e.to],e.to));
					}
				}
			}
			if(dist[t]==inf) return -1;
			rep(v,N) h[v]+=dist[v];
			C d = f;
			for(int v=t;v!=s;v=prevv[v]){
				chmin(d,G[prevv[v]][preve[v]].cap);
			}
			f -= d;
			res += d*h[t];
			for(int v=t;v!=s;v=prevv[v]){
				edge &e=G[prevv[v]][preve[v]];
				e.cap-=d;
				G[v][e.rev].cap+=d;
			}
		}
		return res;
	}
};


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);

	const int S = 101;
	int N; cin >> N;
	V<int> jx(N),jy(N);
	V<ll> jv(N);
	rep(i,N){
		cin >> jx[i] >> jy[i] >> jv[i];
		jx[i]--,jy[i]--;
	}
	int M; cin >> M;
	V<int> L_(S,N),R_(S,N),D_(S,N),U_(S,N);
	rep(i,M){
		char c; int a,b; cin >> c >> a >> b; a--;
		if(c == 'L') L_[a] = b;
		if(c == 'R') R_[a] = b;
		if(c == 'D') D_[a] = b;
		if(c == 'U') U_[a] = b;
	}
	ll ans = 0;
	rep1(K,N){
		V<int> L=L_,D=D_,R(S),U(S);
		rep(i,S-1){
			R[i] = max(K - R_[i+1],0);
			U[i] = max(K - U_[i+1],0);
		}
		rep(i,S){
			chmin(L[i],K);
			chmin(D[i],K);
		}
		per(i,S-1){
			chmin(L[i],L[i+1]);
			chmin(D[i],D[i+1]);
		}
		rep1(i,S-1){
			chmax(R[i],R[i-1]);
			chmax(U[i],U[i-1]);
		}
		show("=====================");
		show(K);
		show(L);show(R);

		int FN = 1+S+N+S+1;
		MinCostFlow MCF(FN);
		int SS = 0, TT = 1;
		auto f = [&](int i){return i+2;};
		auto g = [&](int i){return i+2+S;};
		auto h = [&](int i){return i+2+S+N;};
		bool ok = true;
		{
			rep(i,S){
				int cap = L[i] - (i==0 ? 0 : L[i-1]);
				MCF.add_edge(SS,f(i),cap,0);
			}
			rep(i,S-1){
				int cap = L[i] - R[i];
				if(cap<0) ok = false;
				MCF.add_edge(f(i),f(i+1),cap,0);
			}
		}
		{
			rep(i,S){
				int cap = D[i] - (i==0 ? 0 : D[i-1]);
				MCF.add_edge(h(i),TT,cap,0);
			}
			rep(i,S-1){
				int cap = D[i] - U[i];
				if(cap<0) ok = false;
				MCF.add_edge(h(i+1),h(i),cap,0);
			}
		}
		show(ok);
		if(!ok) continue;
		const ll inf = TEN(15);
		rep(i,N){
			MCF.add_edge(f(jx[i]),g(i),1,inf-jv[i]);
			MCF.add_edge(g(i),h(jy[i]),1,0);
		}
		ll F = MCF.min_cost_flow(SS,TT,K);
		show(F);
		if(F == -1) continue;
		F = inf * K - F;
		chmax(ans,F);
	}
	cout << ans << endl;
}


Measured memory_bytes: 384