#include <cstring>
#include <iostream>
#include <queue>

#define DEBUG() std::cerr << __FUNCTION__ << " " << __LINE__ << std::endl

using i64 = long long;

namespace flw {
	const int N = 5000 + 7, M = 5000000 + 7;
	const int INF = 1 << 28;
	struct flow {
		int n, st, ed;
		int vis[N];
		i64 dis[N];
		struct edge {
			int to, nex, cap; i64 wei;
		} e[M];
		int fir[N], cur[N], eid;
		int maxflow;
		i64 mincost;

		void init() {
			eid = 1;
			std::fill(fir + 1, fir + n + 1, 0);
			st = ed = n = 0;
		}
		void addedge(int u, int v, int c, i64 w) {
			e[++eid] = (edge){ v, fir[u], c, w }, fir[u] = eid;
		}
		void addflow(int u, int v, int c, i64 w) {
			addedge(u, v, c, w), addedge(v, u, 0, -w);
		}
		void dinic() {
			maxflow = mincost = 0;
			int f;
			while (bfs())
				while (f = dfs(st, INF)) maxflow += f, mincost += f * dis[st];
		}
		int bfs() {
			std::fill(dis + 1, dis + n + 1, 1ll << 60),
			std::fill(vis + 1, vis + n + 1, 0);
			std::copy(fir + 1, fir + n + 1, cur + 1);
			static std::queue<int> q;
			dis[ed] = 0, vis[ed] = 1, q.push(ed);
			for (int s; q.size(); ) {
				s = q.front(), q.pop();
				for (int i = fir[s]; i; i = e[i].nex)
					if (e[i ^ 1].cap && dis[e[i].to] > dis[s] - e[i].wei) {
						dis[e[i].to] = dis[s] - e[i].wei;
						if (!vis[e[i].to])
							vis[e[i].to] = 1, q.push(e[i].to);
					}
				vis[s] = 0;
			}
			return dis[st] < 1ll << 60;
		}
		i64 dfs(int s, int f) {
			if (s == ed) return f;
			vis[s] = 1;
			int u = 0, t;
			for (int& i = cur[s]; i; i = e[i].nex) {
				if (!e[i].cap || vis[e[i].to] || dis[s] != dis[e[i].to] + e[i].wei) continue;
				t = dfs(e[i].to, std::min(f - u, e[i].cap));
				e[i].cap -= t, e[i ^ 1].cap += t, u += t;
				if (f == u) break;
			}
			return vis[s] = 0, u;
		}
	};
}

const int X = 100 + 7, N = 80 + 7, M = 320 + 7;

int n, m;
int u[N], v[N];
i64 w[N];
int x[M], y[M], z[M];
int llm[N], rlm[N], dlm[N], ulm[N];
flw::flow f;
i64 ans;

int main() {
//	freopen("code.in", "r", stdin);
//	freopen("code.out", "w", stdout);

	scanf("%d", &n);
	for (int i = 1; i <= n; ++i)
		scanf("%d%d%lld", u + i, v + i, w + i);
	scanf("%d", &m);
	for (int i = 1; i <= m; ++i) {
		char c[3];
		scanf("%s%d%d", c, x + i, y + i);
		if (y[i] >= n) { --i; --m; continue; }
		z[i] = c[0];
	}

	for (int k = 1; k <= n; ++k) {
		f.init();
		f.st = 2 * (n + k) + 1, f.ed = f.n = f.st + 1;
		for (int i = 1; i <= n; ++i)
			f.addflow(i, n + i, 1, -w[i]);
		memset(llm, 0, sizeof llm);
		memset(dlm, 0, sizeof dlm);
		memset(rlm, 0x3f, sizeof rlm);
		memset(ulm, 0x3f, sizeof ulm);
		for (int i = 1; i <= m; ++i) {
			if (y[i] >= k) continue;
			if (z[i] == 'L') llm[y[i] + 1] = std::max(llm[y[i] + 1], x[i] + 1);
			if (z[i] == 'R') rlm[k - y[i]] = std::min(rlm[k - y[i]], x[i] - 1);
			if (z[i] == 'D') dlm[y[i] + 1] = std::max(dlm[y[i] + 1], x[i] + 1);
			if (z[i] == 'U') ulm[k - y[i]] = std::min(ulm[k - y[i]], x[i] - 1);
		}
		for (int i = 1; i <= k; ++i)
			llm[i] = std::max(llm[i], llm[i - 1]),
			dlm[i] = std::max(dlm[i], dlm[i - 1]);
		for (int i = k; i; --i)
			rlm[i] = std::min(rlm[i], rlm[i + 1]),
			ulm[i] = std::min(ulm[i], ulm[i + 1]);
		for (int i = 1; i <= k; ++i) {
			f.addflow(f.st, 2 * n + i, 1, 0);
			f.addflow(2 * n + k + i, f.ed, 1, 0);
			for (int j = 1; j <= n; ++j) {
				if (llm[i] <= u[j] && u[j] <= rlm[i]) f.addflow(2 * n + i, j, 1, 0);
				if (dlm[i] <= v[j] && v[j] <= ulm[i]) f.addflow(n + j, 2 * n + k + i, 1, 0);
			}
		}
		f.dinic();
		if (f.maxflow == k) ans = std::max(ans, -f.mincost);
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 768