#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pi = pair<int, int>;
const int MAXN = 405;
const int MAXC = 100;
const int mod = 1e9 + 7;

struct dinic{
	struct edg{ int pos, cap, rev; };
	vector<edg> gph[MAXN];
	void clear(){ for(int i=0; i<MAXN; i++) gph[i].clear(); }
	void add_edge(int s, int e, int x){
		gph[s].push_back({e, x, (int)gph[e].size()});
		gph[e].push_back({s, 0, (int)gph[s].size()-1});
	}
	int dis[MAXN], pnt[MAXN];
	bool bfs(int src, int sink){
		memset(dis, 0, sizeof(dis));
		memset(pnt, 0, sizeof(pnt));
		queue<int> que;
		que.push(src);
		dis[src] = 1;
		while(!que.empty()){
			int x = que.front();
			que.pop();
			for(auto &e : gph[x]){
				if(e.cap > 0 && !dis[e.pos]){
					dis[e.pos] = dis[x] + 1;
					que.push(e.pos);
				}
			}
		}
		return dis[sink] > 0;
	}
	int dfs(int x, int sink, int f){
		if(x == sink) return f;
		for(; pnt[x] < gph[x].size(); pnt[x]++){
			edg e = gph[x][pnt[x]];
			if(e.cap > 0 && dis[e.pos] == dis[x] + 1){
				int w = dfs(e.pos, sink, min(f, e.cap));
				if(w){
					gph[x][pnt[x]].cap -= w;
					gph[e.pos][e.rev].cap += w;
					return w;
				}
			}
		}
		return 0;
	}
	lint match(int src, int sink){
		lint ret = 0;
		while(bfs(src, sink)){
			int r;
			while((r = dfs(src, sink, 2e9))) ret += r;
		}
		return ret;
	}
}mf;

struct MCMF{
	struct edg{ int pos, cap, rev; lint cost; };
	vector<edg> gph[MAXN];
	void clear(){
		for(int i=0; i<MAXN; i++) gph[i].clear();
	}
	void add_edge(int s, int e, int x, lint c){
		gph[s].push_back({e, x, (int)gph[e].size(), c});
		gph[e].push_back({s, 0, (int)gph[s].size()-1, -c});
	}
	lint dist[MAXN];
	int pa[MAXN], pe[MAXN];
	bool inque[MAXN];
	bool spfa(int src, int sink){
		memset(dist, 0x3f, sizeof(dist));
		memset(inque, 0, sizeof(inque));
		queue<int> que;
		dist[src] = 0;
		inque[src] = 1;
		que.push(src);
		bool ok = 0;
		while(!que.empty()){
			int x = que.front();
			que.pop();
			if(x == sink) ok = 1;
			inque[x] = 0;
			for(int i=0; i<gph[x].size(); i++){
				edg e = gph[x][i];
				if(e.cap > 0 && dist[e.pos] > dist[x] + e.cost){
					dist[e.pos] = dist[x] + e.cost;
					pa[e.pos] = x;
					pe[e.pos] = i;
					if(!inque[e.pos]){
						inque[e.pos] = 1;
						que.push(e.pos);
					}
				}
			}
		}
		return ok;
	}
	lint match(int src, int sink){
		lint ret = 0;
		while(spfa(src, sink)){
			int cap = 1e9;
			for(int pos = sink; pos != src; pos = pa[pos]){
				cap = min(cap, gph[pa[pos]][pe[pos]].cap);
			}
			ret += dist[sink] * cap;
			for(int pos = sink; pos != src; pos = pa[pos]){
				int rev = gph[pa[pos]][pe[pos]].rev;
				gph[pa[pos]][pe[pos]].cap -= cap;
				gph[pos][rev].cap += cap;
			}
		}
		return ret;
	}
	lint neomatch(int src, int sink){
		lint ret = 0;
		while(spfa(src, sink)){
			int cap = 1e9;
			for(int pos = sink; pos != src; pos = pa[pos]){
				cap = min(cap, gph[pa[pos]][pe[pos]].cap);
			}
			if(dist[sink] >= 0) break;
			ret += dist[sink] * cap;
			for(int pos = sink; pos != src; pos = pa[pos]){
				int rev = gph[pa[pos]][pe[pos]].rev;
				gph[pa[pos]][pe[pos]].cap -= cap;
				gph[pos][rev].cap += cap;
			}
		}
		return ret;
	}
}mcmf;

struct LRMCMF{
	lint lsum;
	void clear(){
		lsum = 0;
		mcmf.clear();
		mf.clear();
	}
	void add_edge(int s, int e, int l, int r, lint v){
		lsum += l;
		mf.add_edge(s + 2, e + 2, r - l);
		mf.add_edge(0, e + 2, l);
		mf.add_edge(s + 2, 1, l);
		mcmf.add_edge(s + 2, e + 2, r - l, v);
		mcmf.add_edge(0, e + 2, l, v);
		mcmf.add_edge(s + 2, 1, l, v);
	}
	lint solve(int s, int e){
		mf.add_edge(e+2, s+2, 1e9); // to reduce as maxflow with lower bounds, in circulation problem skip this line
		mcmf.add_edge(e + 2, s + 2, 1e9, 0);
		if(lsum == mf.match(0, 1)){
			lint ans = mcmf.match(0, 1);
			ans += mcmf.neomatch(s + 2, e + 2);
			return ans;
		}
		return 0;
		// to get maximum LR flow, run maxflow from s+2 to e+2 again
	}
}SOLVER;

int n, m;
lint A[MAXN][MAXN];
char buf[MAXN][5];
int x[MAXN], y[MAXN];
pi bx[MAXN], by[MAXN];

lint solve(int k){
	SOLVER.clear();
	fill(bx, bx + MAXN, pi(0, k));
	fill(by, by + MAXN, pi(0, k));
	bx[0] = by[0] = pi(0, 0);
	for(int i=0; i<m; i++){
		if(*buf[i] == 'L'){
			bx[x[i]].second = min(bx[x[i]].second, y[i]);
		}
		if(*buf[i] == 'R'){
			bx[x[i] - 1].first = max(bx[x[i] - 1].first, k - y[i]);
		}
		if(*buf[i] == 'D'){
			by[x[i]].second = min(by[x[i]].second, y[i]);
		}
		if(*buf[i] == 'U'){
			by[x[i] - 1].first = max(by[x[i] - 1].first, k - y[i]);
		}
	}
	for(int i=0; i<MAXN; i++){
		if(bx[i].second < bx[i].first) return 0;
		if(by[i].second < by[i].first) return 0;
	}
	SOLVER.add_edge(0, MAXC + 1, k, k, 0);
	SOLVER.add_edge(MAXC * 2 + 2, MAXC * 2 + 3, k, k, 0);
	for(int i=MAXC; i>=1; i--){
		SOLVER.add_edge(i + 1, i, bx[i].first, bx[i].second, 0); 
		SOLVER.add_edge(MAXC + i + 1, MAXC + i + 2, by[i].first, by[i].second, 0);
	}
	for(int i=1; i<=MAXC; i++){
		for(int j=1; j<=MAXC; j++){
			if(A[i][j]) SOLVER.add_edge(i, j + MAXC + 1, 0, 1, -A[i][j]);
		}
	}
//	cout << k << endl;
	return -SOLVER.solve(0, 2 * MAXC + 3);
}


int main(){
	cin >> n;
	for(int i=0; i<n; i++){
		int x, y; lint z;
		cin >> x >> y >> z;
		A[x][y] = z;
	}
	cin >> m;
	for(int i=0; i<m; i++){
		cin >> buf[i] >> x[i] >> y[i];
	}
	lint ret = 0;
	for(int i=1; i<=n; i++) ret = max(ret, solve(i));
	cout << ret << endl;
}


Measured memory_bytes: 640