#include <bits/stdc++.h>

typedef long long ll;
const int N = 108, M = 324;

struct jewel {
	int x, y; ll v;
	jewel * read() {return scanf("%d%d%lld", &x, &y, &v), this;}
} a[N];

struct condition {
	char ty;
	int pos, lim;
	condition * read() {static char _[4]; return scanf("%s%d%d", _, &pos, &lim), ty = *_, this;}
} c[M];

int n, m;
int xl[N], xu[N], yl[N], yu[N];

inline void up(int &x, const int y) {x < y ? x = y : 0;}
inline void down(int &x, const int y) {x > y ? x = y : 0;}
inline void up(ll &x, const ll y) {x < y ? x = y : 0;}

namespace CF {
	#define ad(x) ((x - 1 ^ 1) + 1)

	const int N = 400, M = 100000;
	const ll INF = 0x7f7f7f7f7f7f7f7fll;

	struct edge {
		int u, v, f; ll c;
		edge (int u0 = 0, int v0 = 0, ll c0 = 0, int f0 = 0) : u(u0), v(v0), f(f0), c(c0) {}
	} e[M];

	int V = 2, E = 0, si = 1, ti = 2, flow;
	ll cost;
	int first[N], next[M];
	int cur[N], que[M << 1];
	ll dep[N];
	bool in_que[N], used[N];

	inline void addedge(int u, int v, ll c, int f) {
		e[++E] = edge(u, v, c, f), next[E] = first[u], first[u] = E;
		e[++E] = edge(v, u, -c), next[E] = first[v], first[v] = E;
	}

	bool bfs() {
		int h = M, t = h + 1, i, x, y;
		memset(dep, 127, sizeof dep);
		que[h] = ti, dep[ti] = 0, in_que[ti] = true;
		for (; h < t; ) {
			x = que[h++], in_que[x] = false;
			for (i = first[x]; i; i = next[i])
				if (dep[y = e[i].v] > dep[x] - e[i].c && e[ad(i)].f) {
					dep[y] = dep[x] - e[i].c;
					if (!in_que[y])
						in_que[y] = true, (dep[y] >= dep[que[h]] ? que[t++] : que[--h]) = y;
				}
		}
		return dep[si] < INF;
	}

	int dfs(int x, int lim) {
		int a, c, f = 0;
		if (x == ti || !lim) return lim;
		used[x] = true;
		for (int &i = cur[x]; i; i = next[i])
			if (dep[e[i].v] == dep[x] - e[i].c && e[i].f && !used[e[i].v]) {
				a = std::min(lim - f, e[i].f);
				c = dfs(e[i].v, a);
				e[i].f -= c, e[ad(i)].f += c;
				if ((f += c) == lim) return f;
			}
		return f;
	}

	inline void reset() {E = 0, memset(first, 0, sizeof first);}

	void Dinic() {
		int f;
		for (cost = flow = 0; bfs(); ) {
			memcpy(cur, first, sizeof cur);
			memset(used, 0, sizeof used);
			flow += f = dfs(si, INT_MAX);
			cost += dep[si] * f;
		}
	}
}

ll solve(int num) {
	int i, j;
	std::fill(xl, xl + num, 1), std::fill(xu, xu + num, 100);
	std::fill(yl, yl + num, 1), std::fill(yu, yu + num, 100);
	for (i = 0; i < m; ++i) if (c[i].lim < num)
		switch (c[i].ty) {
			case 76: up(xl[ c[i].lim ], c[i].pos + 1); break;
			case 68: up(yl[ c[i].lim ], c[i].pos + 1); break;
			case 82: down(xu[ num - c[i].lim - 1 ], c[i].pos - 1); break;
			case 85: down(yu[ num - c[i].lim - 1 ], c[i].pos - 1); break;
		}
	for (i = 1; i < num; ++i) up(xl[i], xl[i - 1]), up(yl[i], yl[i - 1]);
	for (i = num - 2; i >= 0; --i) down(xu[i], xu[i + 1]), down(yu[i], yu[i + 1]);
	CF::reset();
	for (i = 0; i < num; ++i) {
		CF::addedge(1, 203 + i, 0, 1), CF::addedge(203 + num + i, 2, 0, 1);
		for (j = xl[i]; j <= xu[i]; ++j) CF::addedge(203 + i, 2 + j, 0, 1);
		for (j = yl[i]; j <= yu[i]; ++j) CF::addedge(102 + j, 203 + num + i, 0, 1);
	}
	for (i = 0; i < n; ++i) CF::addedge(2 + a[i].x, 102 + a[i].y, -a[i].v, 1);
	CF::Dinic();
	return CF::flow == num ? -CF::cost : 0;
}

int main() {
	int i; ll ans = 0;
	scanf("%d", &n);
	for (i = 0; i < n; ++i) a[i].read();
	scanf("%d", &m);
	for (i = 0; i < m; ++i) c[i].read();
	for (i = 1; i <= n; ++i) up(ans, solve(i));
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 2816