#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)

typedef long long ll;
typedef pair<ll,ll> P;

class minCostFlow {

	struct edge { ll to, cap, cost, rev; };

	ll V;
	vector<vector<edge>> G;
	vector<ll> dist;
	vector<ll> prevv;
	vector<ll> preve;

public:

	minCostFlow(ll n): G(n), dist(n), prevv(n), preve(n), V(n){
	}

	void addEdge(ll from, ll to, ll cap, ll cost) {
		G[from].push_back((edge){to, cap, cost, (ll)G[to].size()});
		G[to].push_back((edge){from, 0, -cost, (ll)G[from].size() - 1});
	}

	ll solve(ll s, ll t, ll f) {
		ll ret = 0;
		while(f > 0) {
			fill(dist.begin(), dist.end(), LLINF);
			dist[s] = 0;
			bool update = true;
			while(update) {
				update = false;
				for(ll v = 0;v < V;v++) {
					if(dist[v] == LLINF)continue;
					for(ll i = 0;i < G[v].size();i++) {
						edge &e = G[v][i];
						if(e.cap > 0 && dist[e.to] > dist[v] + e.cost) {
							dist[e.to] = dist[v] + e.cost;
							prevv[e.to] = v;
							preve[e.to] = i;
							update = true;
						}
					}
				}
			}
			if(dist[t] == LLINF) {
				return LLINF;//流せない
			}

			ll d = f;
			for(ll v = t;v != s;v = prevv[v]) {
				d = min(d, G[prevv[v]][preve[v]].cap);
			}
			f -= d;
			ret += d * dist[t];
			for(ll v = t;v != s;v = prevv[v]) {
				edge &e = G[prevv[v]][preve[v]];
				e.cap -= d;
				G[v][e.rev].cap += d;
			}
		}
		return ret;
	}

};

ll check(vector<pair<P, ll>> &v, vector<pair<char, P>> &t, int k){
	ll cost = 1000000000000000LL;
	int n = v.size();
	int m = t.size();
	
	vector<P> ver(k, MP(0, LLINF));
	vector<P> hor(k, MP(0, LLINF));
	
	REP(i, m){
		char c = t[i].FI;
		P p = t[i].SE;
		if(c == 'L'){
			if(p.SE >= k)continue;
			hor[p.SE].FI = max(hor[p.SE].FI, p.FI + 1);
		}
		else if(c == 'R'){
			if(k - p.SE - 1 < 0)continue;
			hor[k - p.SE - 1].SE = min(hor[k - p.SE - 1].SE, p.FI - 1);
		}
		else if(c == 'D'){
			if(p.SE >= k)continue;
			ver[p.SE].FI = max(ver[p.SE].FI, p.FI + 1);
		}
		else {
			if(k - p.SE - 1 < 0)continue;
			ver[k - p.SE - 1].SE = min(ver[k - p.SE - 1].SE, p.FI - 1);
		}
	}
	
	REP(i, k - 1){
		ver[i + 1].FI = max(ver[i + 1].FI, ver[i].FI);
		hor[i + 1].FI = max(hor[i + 1].FI, hor[i].FI);
		ver[k - i - 2].SE = min(ver[k - i - 2].SE, ver[k - i - 1].SE); 
		hor[k - i - 2].SE = min(hor[k - i - 2].SE, hor[k - i - 1].SE); 
	}
	
	minCostFlow mcf(2 * (n + k) + 10);
	
	ll s = 2 * (k + n);
	ll g = 2 * (k + n) + 1;
	
	REP(i, k){
		ll idA = 2 * n + i;
		ll idB = 2 * n + k + i;
		mcf.addEdge(s, idA, 1, 0);
		mcf.addEdge(idB, g, 1, 0);
	}
	
	REP(i, n){
		P now = v[i].FI;
		ll val = v[i].SE;
		ll idA = i;
		ll idB = i + n;
		mcf.addEdge(idA, idB, 1, cost - val);
		REP(j, k){
			ll idC = 2 * n + j;
			ll idD = 2 * n + k + j;
			if(now.FI >= hor[j].FI && now.FI <= hor[j].SE){
				mcf.addEdge(idC, idA, 1, 0);
			}
			if(now.SE >= ver[j].FI && now.SE <= ver[j].SE){
				mcf.addEdge(idB, idD, 1, 0);
			}
		}
	}
	return k * cost - mcf.solve(s, g, k);
}

int main(){
	
	ll n;cin >> n;
	vector<pair<P, ll>> v(n);
	REP(i, n)cin >> v[i].FI.FI >> v[i].FI.SE >> v[i].SE;
	ll m;cin >> m;
	vector<pair<char, P>> t(m);
	REP(i, m)cin >> t[i].FI >> t[i].SE.FI >> t[i].SE.SE;
	
	ll ans = 0;
	
	for(ll i = 1;i <= n;i++){
		ans = max(ans, check(v, t, i));
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 1220