#include<bits/stdc++.h>
using namespace std;

#define ll long long
namespace flow{
	const ll __ = 1e6 + 7 , _ = 1e5 + 7;
	struct Edge{ll end , upEd , f , c;}Ed[__];
	ll head[_] , cntEd , S , T;
	void clear(){memset(head , 0 , sizeof(head)); cntEd = 1; S = T = 0;}
	void addEd(ll a , ll b , ll c , ll d){Ed[++cntEd] = (Edge){b , head[a] , c , d}; head[a] = cntEd;}
	void addE(ll a , ll b , ll c , ll d){addEd(a , b , c , d); addEd(b , a , 0 , -d);}

	bool vis[_]; queue < ll > q; ll dis[_] , pre[_];
	bool bfs(){
		q.push(S); memset(dis , -0x3f , sizeof(ll) * (T + 2)); dis[S] = 0;
		while(!q.empty()){
			ll t = q.front(); q.pop(); vis[t] = 0;
			for(ll i = head[t] ; i ; i = Ed[i].upEd)
				if(Ed[i].f && dis[Ed[i].end] < dis[t] + Ed[i].c){
					dis[Ed[i].end] = dis[t] + Ed[i].c; pre[Ed[i].end] = i;
					if(!vis[Ed[i].end]){vis[Ed[i].end] = 1; q.push(Ed[i].end);}
				}
		}
		return dis[T] != dis[T + 1];
	}
	
	ll EK(ll s , ll t , ll tarf , ll tarc){
		S = s; T = t; ll sum = 0;
		while(bfs()){
			ll cur = T; --tarf;
			while(cur != S){
				ll t = pre[cur]; cur = Ed[t ^ 1].end; --Ed[t].f; ++Ed[t ^ 1].f;
				if(Ed[t].c == 1e16) --tarc; else if(Ed[t].c == -1e16) ++tarc; else sum += Ed[t].c;
			}
		}
		return !tarf && !tarc ? sum : -1;
	}
}

ll bound[2][2][103] , N , M , X[83] , Y[83]; ll v[83];

signed main(){
	cin >> N; for(ll i = 1 ; i <= N ; ++i) cin >> X[i] >> Y[i] >> v[i];
	cin >> M; memset(bound , 0x3f , sizeof(bound));
	for(ll i = 1 ; i <= M ; ++i){
		char c; ll p , q; cin >> c >> p >> q;
		switch(c){
		case 'L': bound[0][0][p] = min(bound[0][0][p] , q); break;
		case 'R': bound[0][1][p] = min(bound[0][1][p] , q); break;
		case 'U': bound[1][0][p] = min(bound[1][0][p] , q); break;
		case 'D': bound[1][1][p] = min(bound[1][1][p] , q); break;
		}
	}
	ll ans = 0;
	for(ll i = 1 ; i <= N ; ++i){
		flow::clear(); bool flg = bound[0][0][100] >= i && bound[1][1][100] >= i; ll cnt = 0;
		for(ll j = 1 ; j <= 100 ; ++j){
			ll dwn = max(0ll , i - bound[0][0][j - 1]) , up = bound[0][1][j]; flg &= dwn <= up;
			cnt += dwn; flow::addE(j , j + 1 , dwn , (ll)1e16); flow::addE(j , j + 1 , up - dwn , 0);
		}
		for(ll j = 100 ; j ; --j){
			ll dwn = max(0ll , i - bound[1][1][j - 1]) , up = bound[1][0][j]; flg &= dwn <= up;
			cnt += dwn; flow::addE(202 - j , 203 - j , dwn , (ll)1e16); flow::addE(202 - j , 203 - j , up - dwn , 0);
		}
		for(ll j = 1 ; j <= N ; ++j) flow::addE(X[j] + 1 , 202 - Y[j] , 1 , v[j]);
		flow::addE(0 , 1 , i , 0); if(flg) ans = max(ans , flow::EK(0 , 202 , i , cnt));
	}
	cout << ans;
	return 0;
}