#include <bits/stdc++.h>
using namespace std;
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
typedef long long ll;
typedef long double ld;
struct Mcmf {
	const ll INFC = 1LL << 60;
	struct Edge {
		int to;
		int f, cap;
		ll cost;
	};
	int n, src, sink;
	vector<ll> pi, dist;
	vector<int> fromEdge;
	vector<Edge> edges;
	vector<vector<int>> G;
	Mcmf(int _n, int _src = -1, int _sink = -1) : n(_n), src(_src), sink(_sink) {
		G.resize(n);
		dist.resize(n);
		pi.resize(n);
		fromEdge.resize(n);
	}
	void addEdge(int from, int to, int cap, ll cost) {
		G[from].push_back(edges.size());
		edges.push_back({to, 0, cap, cost});
		G[to].push_back(edges.size());
		edges.push_back({from, 0, 0, -cost});
	}
	ll cheapestPath() {
		typedef pair<ll, int> Pair;
		priority_queue<Pair, vector<Pair>, greater<Pair>> pq;
		fill(dist.begin(), dist.begin() + n, INFC);
		dist[src] = 0;
		pq.emplace(dist[src], src);
		while (!pq.empty()) {
			int u = pq.top().second;
			ll cdist = pq.top().first;
			pq.pop();
			if (cdist > dist[u]) continue;
			for (int x : G[u]) {
				Edge e = edges[x];
				if (e.f == e.cap) continue;
				int v = e.to;
				// assert pi[u], pi[v] <<< INFC
				ll val = dist[u] + pi[u] - pi[v] + e.cost;
				if (val < dist[v]) {
					dist[v] = val;
					fromEdge[v] = x;
					pq.emplace(dist[v], v);
				}
			}
		}
		if (dist[sink] >= INFC) return INFC;
		ll cost = dist[sink] + pi[sink];
		for (int k = 0; k < n; ++k)
			pi[k] = min(INFC, pi[k] + dist[k]);
		return cost;
	}
	pair<ll, int> maxFlow() {
		ll totcost = 0;
		int totflow = 0;
		for (;;) {
			ll cost = cheapestPath();
			// Change INFC to 0 to find min-cost flow (not maxflow)
			// Can prove that marginal-cost of flows increases (by exchange)
			if (cost >= INFC) break;
			int flow = INT_MAX;
			for (int x = sink; x != src;) {
				int e = fromEdge[x];
				flow = min(flow, edges[e].cap - edges[e].f);
				x = edges[e ^ 1].to;
			}
			for (int x = sink; x != src;) {
				int e = fromEdge[x];
				edges[e].f += flow;
				edges[e ^ 1].f -= flow;
				x = edges[e ^ 1].to;
			}
			totcost += cost * flow;
			totflow += flow;
			/* Inc one flow at a time
			totcost += cost;
			++totflow;
			for (int x = sink; x != src;) {
				int e = fromEdge[x];
				++edges[e].f;
				--edges[e ^ 1].f;
				x = edges[e ^ 1].to;
			}
			*/
		}
		return {totcost, totflow};
	}
	// pi makes all edges nonnegative, so initialize if necessary
	void initPi() {
		fill(pi.begin(), pi.begin() + n, 0);
	}
};
int main() {
	int n;
	scanf("%d", &n);
	vector<int> x(n), y(n);
	vector<ll> v(n);
	for (int i = 0; i < n; ++i) scanf("%d%d%lld", &x[i], &y[i], &v[i]);
	int m;
	scanf("%d", &m);
	vector<int> a(m), b(m);
	vector<char> t(m);
	for (int i = 0; i < m; ++i) {
		scanf(" %c%d%d", &t[i], &a[i], &b[i]);
	}
	ll ans = 0;
	const ll OFFSET = 1e15;
	for (int k = 1; k <= n; ++k) {
		int nodes = 2 + k * 2 + n * 2;
		Mcmf g(nodes, 0, nodes - 1);
		auto add = [&](int vs, char l, char r, vector<int>& coord) {
			vector<int> L(k + 1, 1), R(k + 1, 100);
			for (int i = 0; i < m; ++i) {
				if (b[i] >= k) continue;
				if (t[i] == l) {
					L[b[i] + 1] = max(L[b[i] + 1], a[i] + 1);
				} else if (t[i] == r) {
					R[k - b[i]] = min(R[k - b[i]], a[i] - 1);
				}
			}
			for (int i = 1; i < k; ++i) {
				L[i + 1] = max(L[i], L[i + 1]);
			}
			for (int i = k - 1; i >= 1; --i) {
				R[i] = min(R[i], R[i + 1]);
			}
			for (int i = 1; i <= k; ++i) {
				for (int j = 0; j < n; ++j) {
					if (coord[j] >= L[i] && coord[j] <= R[i]) {
						if (l == 'L') g.addEdge(i + vs, j + 1, 1, 0);
						else g.addEdge(j + n + 1, i + vs, 1, 0);
					}
				}
			}
		};
		add(2 * n, 'L', 'R', x);
		add(2 * n + k, 'D', 'U', y);
		for (int i = 1; i <= k; ++i) {
			g.addEdge(g.src, i + 2 * n, 1, 0);
			g.addEdge(i + 2 * n + k, g.sink, 1, 0);
		}
		for (int i = 0; i < n; ++i) {
			g.addEdge(i + 1, i + n + 1, 1, OFFSET - v[i]);
		}
		auto ret = g.maxFlow();
		if (ret.second == k) {
			ans = max(ans, k * OFFSET - ret.first);
		}
	}
	printf("%lld\n", ans);
}


Measured memory_bytes: 1496