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

const int N = 85 * 4 + 5;
const int M = N * N;

typedef long long LL;
const LL Base = 1e15, INF = 1e18;

int n, v, m, T[N], a[N], b[N], num, L[N], R[N], U[N], D[N];
char s[N];
long long ans = 0;

struct NODE {
	int x, y;
	long long v;
	void input() {
		scanf("%d%d", &x, &y);
		scanf("%lld", &v);
	}
}P[N];

int chg(char c) {
	if(c == 'L') return 0;
	if(c == 'R') return 1;
	if(c == 'D') return 2;
	return 3;
}

namespace CostFlow {
	
	int fir[N], ne[M], to[M], C[M], cnt, s, t, vis[N], tim, pre[N];
	LL dis[N], Cost[M], res;
	
	void init() {
		res = 0;
		memset(fir, 0, sizeof(fir));
		cnt = 1;
	}
	
	void add(int x, int y, int fl, LL Co) {
		ne[++ cnt] = fir[x];
		fir[x] = cnt;
		to[cnt] = y;
		C[cnt] = fl;
		Cost[cnt] = Co;
	}
	
	void link(int x, int y, int fl, LL Co) {
		add(x, y, fl, Co);
		add(y, x, 0, -Co);
	}
	
	#define Foreachson(i, x) for(int i = fir[x]; i; i = ne[i])
	
	bool inq[N];
	
	bool SPFA(int s, int t) {
		queue <int> q;
		while(!q.empty()) q.pop();
		for(int i = s; i <= t; ++ i) dis[i] = -INF, inq[i] = 0, pre[i] = 0;
		dis[s] = 0;
		q.push(s); inq[s] = 1;
		while(!q.empty()) {
			int ind = q.front(); inq[ind] = 0;
			q.pop();
			Foreachson(i, ind) if(C[i]) {
				int V = to[i];
				if(dis[V] < dis[ind] + Cost[i]) {
					dis[V] = dis[ind] + Cost[i];
					pre[V] = i;
					if(!inq[V]) q.push(V), inq[V] = 1;
				}
			}
		}
		if(dis[t] == -INF) return 0;
		return 1;
	}
	
	LL CostFlow() {
		LL res = 0;
		int tot = 0;
		while(SPFA(s, t)) {
			res += dis[t];
			++ tot;
			int now = t;
			while(now != s) {
				-- C[pre[now]]; ++ C[pre[now] ^ 1];
				now = to[pre[now] ^ 1];
			}
		}
		//cerr << tot << endl;
		return res;
	}
}

LL solve(int num) {
	for(int i = 1; i <= num; ++ i) L[i] = D[i] = 0, R[i] = U[i] = 101;
	for(int i = 1; i <= m; ++ i) {
		if(b[i] >= num) continue;
		if(T[i] == 0) L[b[i] + 1] = max(L[b[i] + 1], a[i] + 1);
		if(T[i] == 2) D[b[i] + 1] = max(D[b[i] + 1], a[i] + 1);
		if(T[i] == 1) R[num - b[i]] = min(R[num - b[i]], a[i] - 1);
		if(T[i] == 3) U[num - b[i]] = min(U[num - b[i]], a[i] - 1);
	}
	for(int i = 1; i < num; ++ i) {
		L[i + 1] = max(L[i + 1], L[i]);
		D[i + 1] = max(D[i + 1], D[i]);
	}
	for(int i = num - 1; i >= 1; -- i) {
		U[i] = min(U[i], U[i + 1]);
		R[i] = min(R[i], R[i + 1]);
	}
	CostFlow :: init();
	int s = 1, t = 2 * num + 2 * n + 2;
	CostFlow :: s = 1, CostFlow :: t = 2 * num + 2 * n + 2;
	
	for(int i = 1; i <= num; ++ i)
	CostFlow :: link(s, 2 * n + 1 + i, 1, 0), 
	CostFlow :: link(2 * n + 1 + num + i, t, 1, 0);
	
	for(int i = 1; i <= n; ++ i) {
		CostFlow :: link(i * 2, i * 2 + 1, 1, P[i].v);
		for(int j = 1; j <= num; ++ j) {
			if(L[j] <= P[i].x && P[i].x <= R[j]) {
				CostFlow :: link(2 * n + 1 + j, i * 2, 1, 0);
			}
			if(D[j] <= P[i].y && P[i].y <= U[j]) {
				CostFlow :: link(i * 2 + 1, 2 * n + num + 1 + j, 1, 0);
			}
		}
	}
	LL res = CostFlow :: CostFlow();
	//cerr << num <<" " << res << endl;
	return res;
}

int main(void) {
	cin >> n;
	for(int i = 1; i <= n; ++ i) P[i].input();
	cin >> m;
	for(int i = 1; i <= m; ++ i) {
		scanf("%s", s);
		T[i] = chg(s[0]);
		scanf("%d%d", &a[i], &b[i]);
	}
	for(num = 1; num <= n; ++ num) {
		ans = max(ans, solve(num));
	}
	cout << ans << endl;
}

Measured memory_bytes: 640