#include <cstdio>
#include <cstring>
#include <algorithm>
#define R register
#define ll long long
#define INF 333222111666555444ll
#define cmin(_A, _B) (_A > _B) ? (_A = _B) : 0
#define cmax(_A, _B) (_A < _B) ? (_A = _B) : 0
#define MIN(_A, _B) (((_A) < (_B)) ? (_A) : (_B))
#define MAX(_A, _B) (((_A) > (_B)) ? (_A) : (_B))

int n, m;

struct Point{
	int x, y;
	ll v;
}p[88];

struct Opt{
	char op;
	int a, b;
}d[333];


struct Flow{
	int cnt;
	int cntp;
	int S, T;
	int fr[333];
	int cur[333];
	int ne[66666];
	int to[66666];
	int c[66666];
	ll w[66666];
	
	void add(R int a, R int b, R int v, R ll co){
//		printf("%d %d %d %lld\n", a, b, v, co);
		ne[++cnt] = fr[a], fr[a] = cnt, to[cnt] = b, c[cnt] = v, w[cnt] = co;
		ne[++cnt] = fr[b], fr[b] = cnt, to[cnt] = a, c[cnt] = 0, w[cnt] = -co;
	}
	
	ll dis[333];
	bool vis[333];
	int q[66666];
	unsigned short head, tail;
	bool spfa(){
		head = tail = 0;
		memset(vis, 0, sizeof(vis));
		memset(dis, 63, sizeof(dis));
		q[++tail] = S, dis[S] = 0;
		while(head != tail){
			R int now = q[++head];
//			printf("%d\n", now);
			vis[now] = false;
			for(R int i = fr[now]; i; i = ne[i]){
				if(c[i] && dis[now] + w[i] < dis[to[i]]){
					dis[to[i]] = dis[now] + w[i];
					if(!vis[to[i]]) vis[to[i]] = true, q[++tail] = to[i];
				}
			}
		}
//		puts("ga");
		if(dis[T] > INF) return false;
		return true;
	}
	
	ll tans;
	int dfs(int a, int flow){
		if(a == T) return flow;
		vis[a] = true;
		int f = flow, tmp;
		for(int &i = cur[a]; i; i = ne[i]){
			if(!vis[to[i]] && c[i] && dis[to[i]] == dis[a] + w[i] && (tmp = dfs(to[i], MIN(f, c[i])))){
				c[i] -= tmp, c[i ^ 1] += tmp, f -= tmp, tans += w[i] * tmp;
				if(!f) {vis[a] = false; return flow;}
			}
		}
		vis[a] = false;
		return flow - f;
	}
	
	int main(){
		tans = 0;
		R int tmp = 0;
		while(spfa()){
			for(R int i = 1; i <= cntp; i++) cur[i] = fr[i];
			tmp += dfs(S, 666);
		}
		return tmp;
	}
	
	int mxx[88], mxy[88];
	int mnx[88], mny[88];
	bool build(int k){
	//	printf("%d\n", k);
		cnt = 1, cntp = 0;
		memset(fr, 0, sizeof(fr));
		for(R int i = 1; i <= k; i++)
			mxx[i] = mxy[i] = 101, mnx[i] = mny[i] = 0;
		for(R int i = 1; i <= m; i++){
			if(d[i].b >= k) continue;
			if(d[i].op == 'L') cmax(mnx[d[i].b + 1], d[i].a);
			if(d[i].op == 'R') cmin(mxx[k - d[i].b], d[i].a);
			if(d[i].op == 'D') cmax(mny[d[i].b + 1], d[i].a);
			if(d[i].op == 'U') cmin(mxy[k - d[i].b], d[i].a);
		}
		for(R int i = 2; i <= k; i++)
			cmax(mnx[i], mnx[i - 1]),
			cmax(mny[i], mny[i - 1]);
		for(R int i = k - 1; i; i--)
			cmin(mxx[i], mxx[i + 1]),
			cmin(mxy[i], mxy[i + 1]);
		for(R int i = 1; i <= k; i++)
			if(mxx[i] - mnx[i] < 2 || mxy[i] - mny[i] < 2) return false;
		for(R int i = 1; i <= n; i++) add(i, i + n, 1, p[i].v);
		for(R int i = 1; i <= k; i++){
			for(R int j = 1; j <= n; j++){
				if(p[j].x > mnx[i] && p[j].x < mxx[i])
					add(2 * n + i, j, 1, 0);
				if(p[j].y > mny[i] && p[j].y < mxy[i])
					add(j + n, 2 * n + k + i, 1, 0);
			}
		}
		cntp = 2 * n + 2 * k;
		S = ++cntp, T = ++cntp;
		for(R int i = 1; i <= k; i++) add(S, 2 * n + i, 1, 0), add(2 * n + k + i, T, 1, 0);
		return true;
	}
}A;

int main(){
	ll ans = 0;
	scanf("%d", &n);
	for(int i = 1; i <= n; i++)
		scanf("%d %d %lld", &p[i].x, &p[i].y, &p[i].v), p[i].v = -p[i].v;
	scanf("%d", &m);
	char tch[3];
	for(R int i = 1; i <= m; i++){
		scanf("%s", tch + 1);
		scanf("%d %d", &d[i].a, &d[i].b);
		d[i].op = tch[1];
	}
	for(R int i = 1; i <= n; i++){
		if(A.build(i)){
			if(A.main() != i) break;
			ans = MIN(ans, A.tans);
		}
		else break;
	}
	printf("%lld\n", -ans);
	return 0;
}

Measured memory_bytes: 512