#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef double db;
#define go(u) for(int i = head[u], v = e[i].to; i; i=e[i].lst, v=e[i].to)
#define rep(i, a, b) for(int i = a; i <= b; ++i)
#define pb push_back
#define re(x) memset(x, 0, sizeof x)
inline int gi() {
    int x = 0,f = 1;
    char ch = getchar();
    while(!isdigit(ch)) { if(ch == '-') f = -1; ch = getchar();}
    while(isdigit(ch)) { x = (x << 3) + (x << 1) + ch - 48; ch = getchar();}
    return x * f;
}
template <typename T> inline bool Max(T &a, T b){return a < b ? a = b, 1 : 0;}
template <typename T> inline bool Min(T &a, T b){return a > b ? a = b, 1 : 0;}
const int N = 407;
const int inf = 1e9;
const LL INF = 1e18;
int n, m;
int x[N], y[N], a[N], b[N], type[N], L[N], R[N];
LL ans, w[N];
char s[10];
namespace MCMF {
	int S, T, edc;
	int head[N], vis[N], cur[N];
	LL dis[N];
	struct edge { int lst, to, cap, flow;LL c;}e[N * N * 2];
	void Add(int a, int b, int c, LL d) {
		e[++edc] = (edge) { head[a], b, c, 0, -d}, head[a] = edc;
		e[++edc] = (edge) { head[b], a, 0, 0, d}, head[b] = edc;
	}
	bool spfa() {
		memcpy(cur, head, sizeof cur);
		fill(dis, dis + N, INF);
		dis[S] = 0;
		queue<int>Q; Q.push(S);
		while(!Q.empty()) {
			int u = Q.front();Q.pop();
			vis[u] = 0;
			go(u) if(e[i].cap - e[i].flow > 0 && Min(dis[v], dis[u] + e[i].c)) {
				if(!vis[v])
				Q.push(v);
			}
		}
		return dis[T] != INF;
	}
	typedef pair<int, LL> pii;
	#define mp make_pair
	pii dfs(int u, int b) {
		if(u == T || !b) return mp(b, 0);
		vis[u] = 1;
		pii res(0, 0), t;
		for(int &i = cur[u], v = e[i].to; i; i = e[i].lst, v = e[i].to) 
		if(e[i].cap - e[i].flow > 0 && dis[u] + e[i].c == dis[v] && !vis[v]) {
			t = dfs(v, min(b, e[i].cap - e[i].flow));
			res.first += t.first;
			res.second += t.second + e[i].c * t.first;
			e[i].flow += t.first;
			e[i ^ 1].flow -= t.first;
			b -= t.first;
			if(!b) break;
		}
		vis[u] = 0;
		return res;
	}
	LL mcmf() {
		LL res = 0;
		while(spfa()) {
			res += dfs(S, inf).second;
		}
		return -res;
	}
}
int id(char c) {
	if(c == 'L') return 0;
	if(c == 'R') return 1;
	if(c == 'D') return 2;
	if(c == 'U') return 3;
}
int main() {
#ifdef fwat
//	freopen("data.in", "r", stdin);
#endif
	using namespace MCMF;
	n = gi();
	rep(i, 1, n) x[i] = gi(), y[i] = gi(), scanf("%lld", &w[i]);
	m = gi();
	rep(i, 1, m) {
		scanf("%s%d%d", s, &a[i], &b[i]);
		type[i] = id(s[0]);
	}
	S = 401, T = 402;
	for(int tot = n; tot; --tot) {
		edc = 1;
		re(head);
		rep(i, 1, tot) L[i] = 1, R[i] = 100;
		rep(i, 1, m) {
			if(type[i] == 0) for(int j = b[i] + 1; j <= tot; ++j) Max(L[j], a[i] + 1);
			if(type[i] == 1) for(int j = tot - b[i]; j > 0; --j)  Min(R[j], a[i] - 1);
		}
		rep(i, 1, tot) {
			Add(S, i, 1, 0);
			rep(j, L[i], R[i]) Add(i, j + 100, 1, 0);
		}
		rep(i, 1, tot) L[i] = 1, R[i] = 100;
		rep(i, 1, m) {
			if(type[i] == 2) for(int j = b[i] + 1; j <= tot; ++j) Max(L[j], a[i] + 1);
			if(type[i] == 3) for(int j = tot - b[i]; j > 0; --j)  Min(R[j], a[i] - 1);
		}
		rep(i, 1, tot) {
			Add(i + 300, T, 1, 0);
			rep(j, L[i], R[i]) Add(j + 200, i + 300, 1, 0);
		}
		rep(i, 1, n) Add(x[i] + 100, y[i] + 200, 1, w[i]);
		Max(ans, mcmf());
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 896