#include <bits/stdc++.h>

#ifdef __WIN32
#define LLFORMAT "I64"
#else
#define LLFORMAT "ll"
#endif

using namespace std;

struct edge {
	int to, cap, rev;
	long long cst;

	edge() {}
	edge(int to, int cap, int rev, long long cst): to(to), cap(cap), rev(rev), cst(cst) {}
};

int main() {
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> x(n), y(n), ordx(n), ordy(n);
	vector<long long> v(n);
	for (int i = 0; i < n; ++i) cin >> x[i] >> y[i] >> v[i], ordx[i] = i, ordy[i] = i;
	sort(ordx.begin(), ordx.end(), [&](int a, int b) { return x[a] > x[b]; });
	sort(ordy.begin(), ordy.end(), [&](int a, int b) { return y[a] > y[b]; });
	int m;
	cin >> m;
	vector<pair<int, int> > liml, limd;
	for (int i = 0; i < m; ++i) {
		char t;
		int a, b;
		cin >> t >> a >> b;
		++b;
		if(t == 'L') liml.push_back(make_pair(a, b));
		else if(t == 'R') liml.push_back(make_pair(a - 1, -b));
		else if(t == 'D') limd.push_back(make_pair(a, b));
		else limd.push_back(make_pair(a - 1, -b));
	}
	sort(liml.begin(), liml.end());
	sort(limd.begin(), limd.end());
	reverse(liml.begin(), liml.end());
	reverse(limd.begin(), limd.end());
	long long ans = 0;
	vector<vector<edge> > g(n + m + 5);
	vector<long long> dst(n + m + 5);
	vector<int> pree(n + m + 5), prev(n + m + 5);
	vector<bool> in(n + m + 5);
	for (int chs = 0; chs <= n; ++chs) {
		fill(g.begin(), g.end(), vector<edge>());
		int S = g.size() - 1, T = g.size() - 2, SS = g.size() - 3, TT = g.size() - 4, lim = g.size() - 5;
		int total_low = 0;
		auto add_edge = [&](int from, int to, int low, int hgh, long long cst) {
			low = max(low, 0);
			total_low += low;
			auto add_edge = [&](int from, int to, int cap, long long cst) {
				if(!cap) return;
				g[from].push_back(edge(to, cap, g[to].size(), cst));
				g[to].push_back(edge(from, 0, g[from].size() - 1, -cst));
				return;
			};
			add_edge(from, to, hgh - low, cst);
			add_edge(SS, to, low, 0);
			add_edge(from, TT, low, 0);
			return;
		};
		add_edge(S, lim, chs, chs, 0);
		int j = 0, pre = lim;
		for (int i = 0; i < liml.size(); ++i) {
			int u = i, a = liml[i].first, b = liml[i].second;
			while(j < n) {
				int i = ordx[j];
				if(x[i] <= a) break;
				add_edge(pre, i + m, 0, 1, -v[i]);
				++j;
			}
			if(b > 0) add_edge(pre, u, 0, b - 1, 0);
			else add_edge(pre, u, chs - (-b - 1), n, 0);
			pre = u;
		}
		while(j < n) {
			int i = ordx[j];
			add_edge(pre, i + m, 0, 1, -v[i]);
			++j;
		}
		j = 0, pre = T;
		for (int i = 0; i < limd.size(); ++i) {
			int u = m - 1 - i, a = limd[i].first, b = limd[i].second;
			while(j < n) {
				int i = ordy[j];
				if(y[i] <= a) break;
				add_edge(i + m, pre, 0, 1, 0);
				++j;
			}
			if(b > 0) add_edge(u, pre, 0, b - 1, 0);
			else add_edge(u, pre, chs - (-b - 1), n, 0);
			pre = u;
		}
		while(j < n) {
			int i = ordy[j];
			add_edge(i + m, pre, 0, 1, 0);
			++j;
		}
		static const int oo = 1e9;
		add_edge(T, S, 0, oo, 0);
		auto mcmf = [&](int S, int T) {
			auto spfa = [&](int S, int T) {
				static const long long oo = 1ll << 62;
				fill(dst.begin(), dst.end(), oo);
				fill(in.begin(), in.end(),false);
				queue<int> q;
				q.push(S);
				in[S] = true;
				dst[S] = 0;
				while(q.size()) {
					int u = q.front();
					q.pop();
					in[u] = false;
					for (int i = 0; i < g[u].size(); ++i) if(g[u][i].cap) {
						int v = g[u][i].to;
						long long w = dst[u] + g[u][i].cst;
						if(dst[v] > w) {
							dst[v] = w;
							prev[v] = u;
							pree[v] = i;
							if(!in[v]) in[v] = true, q.push(v);
						}
					}
				}
				return dst[T] < oo;
			};
			int flow = 0;
			long long cost = 0;
			while(spfa(S, T)) {
				int mn = oo;
				for (int u = T; u != S; u = prev[u]) mn = min(mn, g[prev[u]][pree[u]].cap);
				flow += mn;
				cost += mn * dst[T];
				for (int u = T; u != S; u = prev[u]) {
					int v = prev[u], i = pree[u];
					g[v][i].cap -= mn;
					g[u][g[v][i].rev].cap += mn;
				}
			}
			return make_pair(flow, cost);
		};
		auto res = mcmf(SS, TT);
		if(res.first != total_low) continue;
		ans = min(ans, mcmf(S, T).second + res.second);
	}
	cout << -ans << endl;
	return 0;
}

Measured memory_bytes: 384