#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define MOD @
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

template <class T> void chmax(T &a, const T &b) { a = max(a, b); }
template <class T> void chmin(T &a, const T &b) { a = min(a, b); }

namespace MCF {
	#define MAXN 300
	#define MAXM 5050
	#define wint i64
	#define cint i64
	const wint wEPS = 0;
	const wint wINF = 1LL << 60LL;
	const cint cEPS = 0;
	const cint cINF = 1LL << 60LL;
	int n, m, ptr[MAXN], next[MAXM], zu[MAXM];
	wint capa[MAXM], tof; // tof: possible flow, toc: mincost
	cint cost[MAXM], toc, d[MAXN], pot[MAXN];
	int vis[MAXN], pree[MAXN];
	void init(int _n) {
		n = _n; m = 0; memset(ptr, ~0, n * 4);
	}
	void ae(int u, int v, wint w, cint c) {
		next[m] = ptr[u]; ptr[u] = m; zu[m] = v; capa[m] = w; cost[m] = +c; ++m;
		next[m] = ptr[v]; ptr[v] = m; zu[m] = u; capa[m] = 0; cost[m] = -c; ++m;
	} // MAXM should be at least 2 * (num of edges) !!
	bool solve(int src, int ink, wint flo = wINF) {
		int i, u, v;
		wint f;
		cint c, cc;
		memset(pot, 0, n * sizeof(cint));

		for (bool cont = 1; cont; ) {
			cont = 0;
			for (u = 0; u < n; ++u) for (i = ptr[u]; ~i; i = next[i]) if (capa[i] > wEPS) {
				if (pot[zu[i]] > pot[u] + cost[i] + cEPS) {
					pot[zu[i]] = pot[u] + cost[i]; cont = 1;
				}
			}
		}
		for (toc = 0, tof = 0; tof + wEPS < flo; ) {
			typedef pair<cint,int> node;
			priority_queue< node,vector<node>,greater<node> > q;
			for (u = 0; u < n; ++u) { d[u] = cINF; vis[u] = 0; }
			for (q.push(make_pair(d[src] = 0, src)); !q.empty(); ) {
				c = q.top().first; u = q.top().second; q.pop();
				if (vis[u]++) continue;
				for (i = ptr[u]; ~i; i = next[i]) if (capa[i] > wEPS) {
					cc = c + cost[i] + pot[u] - pot[v = zu[i]];
					if (d[v] > cc) { q.push(make_pair(d[v] = cc, v)); pree[v] = i; }
				}
			}
			if (!vis[ink]) return 0;
			f = flo - tof;
			for (v = ink; v != src; v = zu[i ^ 1]) { i = pree[v]; chmin(f, capa[i]); }
			for (v = ink; v != src; v = zu[i ^ 1]) { i = pree[v]; capa[i] -= f; capa[i ^ 1] += f; }
			tof += f;
			toc += f * (d[ink] - pot[src] + pot[ink]);
			for (u = 0; u < n; ++u) pot[u] += d[u];
		}
		return 1;
	} // returns whether (max_flow >= flo)
}

int N, M;
int X[80], Y[80]; i64 V[80];

int Xa[101], Xb[101], Ya[101], Yb[101];
int lo[101], hi[101];

void preproc(int *xa, int *xb)
{
	for (int i = 99; i >= 0; --i) chmin(xa[i], xa[i + 1]);
	for (int i = 1; i <= 100; ++i) chmin(xb[i], xb[i - 1]);
}
void compute_lohi(int *xa, int *xb, int n)
{
	for (int i = 0; i < 100; ++i) {
		hi[i] = xb[i + 1];
		lo[i] = max(n - xa[i], 0);
	}
}

int main()
{
	scanf("%d", &N);
	for (int i = 0; i < N; ++i) {
		scanf("%d%d%lld", X + i, Y + i, V + i);
	}

	fill(Xa, Xa + 101, N);
	fill(Xb, Xb + 101, N);
	fill(Ya, Ya + 101, N);
	fill(Yb, Yb + 101, N);
	scanf("%d", &M);
	for (int i = 0; i < M; ++i) {
		char T[2]; int a, b;
		scanf("%s%d%d", T, &a, &b);

		if (T[0] == 'L') chmin(Xa[a], b);
		if (T[0] == 'R') chmin(Xb[a], b);
		if (T[0] == 'D') chmin(Ya[a], b);
		if (T[0] == 'U') chmin(Yb[a], b);
	}

	preproc(Xa, Xb);
	preproc(Ya, Yb);

	i64 ans = 0;
	for (int n = 0; n <= N; ++n) {
		MCF::init(204);

		compute_lohi(Xa, Xb, n);
		int s = 202, t = 203;
		int lo_sum = 0;
		for (int i = 0; i < 100; ++i) {
			if (hi[i] < lo[i]) goto fail;
			MCF::ae(i, i + 1, hi[i] - lo[i], 0);
			MCF::ae(i, t, lo[i], 0);
			MCF::ae(s, i + 1, lo[i], 0);
			lo_sum += lo[i];
		}
		compute_lohi(Ya, Yb, n);
		for (int i = 0; i < 100; ++i) {
			if (hi[i] < lo[i]) goto fail;
			MCF::ae(101 + i + 1, 101 + i, hi[i] - lo[i], 0);
			MCF::ae(101 + i + 1, t, lo[i], 0);
			MCF::ae(s, 101 + i, lo[i], 0);
			lo_sum += lo[i];
		}

		MCF::ae(s, 0, n, 0);
		MCF::ae(101, t, n, 0);

		for (int i = 0; i < N; ++i) {
			MCF::ae(X[i], Y[i] + 101, 1, -V[i]);
		}

		//printf("%d %d\n", lo_sum, n);
		if (MCF::solve(s, t, lo_sum + n)) {
			ans = max(ans, -MCF::toc);
		}

	fail:
		continue;
	}

	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 256