#include<bits/stdc++.h>
using namespace std;
const int MAXN = 505;
const int MAXV = 100;
const int INF  = 1e9;
typedef long long ll;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
namespace MincostFlow {
	const int MAXP = 12005;
	const int MAXQ = 2e5 + 5;
	const long long INF = 1e18;
	struct edge {int dest, flow, pos; ll cost; };
	vector <edge> a[MAXP];
	int n, m, s, t, tot, flow;
	ll dist[MAXP], cost; int path[MAXP], home[MAXP];
	void FlowPath() {
		int p = t, ans = 1e9;
		while (p != s) {
			ans = min(ans, a[path[p]][home[p]].flow);
			p = path[p];
		}
		flow += ans;
		cost += ans * dist[t];
		p = t;
		while (p != s) {
			a[path[p]][home[p]].flow -= ans;
			a[p][a[path[p]][home[p]].pos].flow += ans;
			p = path[p];
		}
	}
	bool spfa() {
		static int q[MAXQ];
		static bool inq[MAXP];
		static int l = 0, r = 0;
		for (int i = 0; i <= r; i++)
			dist[q[i]] = -INF;
		q[l = r = 0] = s, dist[s] = 0, inq[s] = true;
		while (l <= r) {
			int tmp = q[l];
			for (unsigned i = 0; i < a[tmp].size(); i++)
				if (a[tmp][i].flow != 0 && dist[tmp] + a[tmp][i].cost > dist[a[tmp][i].dest]) {
					dist[a[tmp][i].dest] = dist[tmp] + a[tmp][i].cost;
					path[a[tmp][i].dest] = tmp;
					home[a[tmp][i].dest] = i;
					if (!inq[a[tmp][i].dest]) {
						q[++r] = a[tmp][i].dest;
						inq[q[r]] = true;
					}
				}
			l++, inq[tmp] = false;
		}
		return dist[t] != -INF;
	}
	void addedge(int x, int y, int z, ll c) {
		a[x].push_back((edge){y, z, a[y].size(), c});
		a[y].push_back((edge){x, 0, a[x].size() - 1, -c});
	}
	ll work(int n, int ns, int nt, int intend) {
		flow = cost = 0;
		for (int i = 1; i <= n; i++)
			dist[i] = -INF;
		while (spfa())
		FlowPath();
		if (flow < intend) return 0;
		s = ns, t = nt;
		while (spfa() && dist[t] > 0) FlowPath();
		return cost;
	}
	void init() {
		for (int i = 1; i <= tot; i++)
			a[i].clear();
		s = 1; t = tot = 2;
	}
}
int l[MAXN], r[MAXN], u[MAXN], d[MAXN];
int s, t, n, m, tot, x[MAXN], y[MAXN]; ll v[MAXN];
int main() {
	read(n);
	for (int i = 1; i <= n; i++)
		read(x[i]), read(y[i]), read(v[i]);
	read(m);
	for (int i = 0; i <= MAXV + 1; i++)
		l[i] = r[i] = u[i] = d[i] = n;
	l[0] = d[0] = 0, r[MAXV + 1] = u[MAXV + 1] = 0;
	for (int i = 1; i <= m; i++) {
		char c; int x, y;
		scanf("\n%c%d%d", &c, &x, &y);
		if (c == 'L') l[x] = y;
		if (c == 'R') r[x] = y;
		if (c == 'U') u[x] = y;
		if (c == 'D') d[x] = y;
	}
	for (int i = 1, j = MAXV; i <= MAXV; i++, j--) {
		chkmin(r[i], r[i - 1]), chkmin(u[i], u[i - 1]);
		chkmin(l[j], l[j + 1]), chkmin(d[j], d[j + 1]);
	}
	ll ans = 0;
	for (int k = 1; k <= n; k++) {
		MincostFlow :: init();
		s = ++MincostFlow :: tot;
		t = ++MincostFlow :: tot;
		bool fail = false; int intend = 0;
		static int xp[MAXN], yp[MAXN], inp[MAXN], outp[MAXN];
		for (int i = 1; i <= n; i++) {
			inp[i] = ++MincostFlow :: tot;
			outp[i] = ++MincostFlow :: tot;
		}
		for (int i = 1; i <= MAXV; i++) {
			xp[i] = ++MincostFlow :: tot;
			yp[i] = ++MincostFlow :: tot;
		}
		MincostFlow :: addedge(t, s, INF, -1e15);
		for (int i = 1; i <= n; i++) {
			MincostFlow :: addedge(inp[i], outp[i], 1, v[i]);
			MincostFlow :: addedge(xp[x[i]], inp[i], 1, 0);
			MincostFlow :: addedge(outp[i], yp[y[i]], 1, 0);
		}
		xp[MAXV + 1] = s, yp[MAXV + 1] = t;
		for (int i = 1; i <= MAXV; i++) {
			int Min, Max;
			Max = min(l[i], k), Min = max(k - r[i + 1], 0), intend += Min;
			if (Min > Max) {fail = true; break; }
			MincostFlow :: addedge(xp[i + 1], xp[i], Max - Min, 0);
			MincostFlow :: addedge(MincostFlow :: s, xp[i], Min, 0);
			MincostFlow :: addedge(xp[i + 1], MincostFlow :: t, Min, 0);
			
			Max = min(d[i], k), Min = max(k - u[i + 1], 0), intend += Min;
			if (Min > Max) {fail = true; break; }
			MincostFlow :: addedge(yp[i], yp[i + 1], Max - Min, 0);
			MincostFlow :: addedge(MincostFlow :: s, yp[i + 1], Min, 0);
			MincostFlow :: addedge(yp[i], MincostFlow :: t, Min, 0);
		}
		if (fail) continue;
		else chkmax(ans, MincostFlow :: work(MincostFlow :: tot, s, t, intend));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640