#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 500;
int n, x[maxn + 10], y[maxn + 10];
ll v[maxn + 10];
char t[maxn + 10];
int a[maxn + 10], b[maxn + 10], m;
int mnx[maxn + 10], mxx[maxn + 10];
int mny[maxn + 10], mxy[maxn + 10];
ll res;

namespace flow {
	typedef long long FlowType, CostType;
	const int maxn = 1e5, maxm = 2e5;
	const FlowType inff = 1e18;
	const CostType infc = 1e18;

	int n, m, s, t;
	vector<int> g[maxn];

	struct Edge {
		int v;
		FlowType cap, flow;
		CostType cost;
	} edge[maxm << 1];

	CostType dist[maxn], h[maxn];

	void Init(int _n, int _s, int _t) {
		n = _n; s = _s; t = _t; m = 0;
		for (int i = 0; i <= n; ++i) g[i].clear();
	}

	void AddEdge(int u, int v, FlowType cap, CostType cost) {
		g[u].push_back(m);
		edge[m++] = (Edge){v, cap, 0, cost};
		g[v].push_back(m);
		edge[m++] = (Edge){u, 0, 0, -cost};
	}

	struct Node {
		int u;
		CostType d;
		bool operator < (const Node &rhs) const {
			return d > rhs.d;
		}
	};

	bool Dijkstra(void) {
		priority_queue<Node> q;
		q.push((Node){s, 0});
		fill(dist, dist + n, infc);
		dist[s] = 0;
		while (!q.empty()) {
			int u = q.top().u;
			CostType d = q.top().d;
			q.pop();
			if (d != dist[u]) continue;
			for (int i = 0; i < g[u].size(); ++i) {
				Edge &e = edge[g[u][i]];
				if (e.flow < e.cap) {
					CostType t = dist[u] + h[u] - h[e.v] + e.cost;
					if (dist[e.v] > t) {
						dist[e.v] = t;
						q.push((Node){e.v, t});
					}
				}
			}
		}
		for (int i = 0; i < n; ++i) {
			h[i] = min(h[i] + dist[i], infc);
		}
		return h[t] != infc;
	}

	bool ins[maxn];
	int cur[maxn];

	FlowType Dfs(int u, FlowType f) {
		if (u == t) return f;
		ins[u] = true;
		FlowType sum = 0;
		for (int &i = cur[u]; i < g[u].size(); ++i) {
			Edge &e = edge[g[u][i]], &r = edge[g[u][i] ^ 1];
			if (e.flow < e.cap && e.cost + h[u] - h[e.v] == 0 && !ins[e.v]) {
				FlowType t = Dfs(e.v, min(f - sum, e.cap - e.flow));
				e.flow += t;
				r.flow -= t;
				sum += t;
				if (sum == f) break;
			}
		}
		ins[u] = false;
		return sum;
	}

	pair<FlowType, CostType> Solve(void) {
		pair<FlowType, CostType> ans(0, 0);
		fill(h, h + n, 0);
		fill(ins, ins + n, false);
		while (Dijkstra()) {
			fill(cur, cur + n, 0);
			FlowType f = Dfs(s, inff);
			ans.first += f;
			ans.second += f * h[t];
		}
		return ans;
	}
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) scanf("%d%d%lld", &x[i], &y[i], &v[i]);
	scanf("%d", &m);
	for (int i = 1; i <= m; ++i) {
		char s[10]; scanf("%s", s);
		t[i] = s[0];
		scanf("%d%d", &a[i], &b[i]);
	}
	for (int i = 1; i <= n; ++i) {
		flow::Init(2 + n * 2 + i * 2 + 1, 1, 2);
		for (int j = 1; j <= i; ++j) {
			mnx[j] = 0; mxx[j] = 200;
			mny[j] = 0; mxy[j] = 200;
		}
		for (int j = 1; j <= m; ++j) {
			if (t[j] == 'L') {
				for (int k = b[j] + 1; k <= i; ++k)
					mnx[k] = max(mnx[k], a[j] + 1);
			} else if (t[j] == 'R') {
				for (int k = i - b[j]; k >= 1; --k)
					mxx[k] = min(mxx[k], a[j] - 1);
			} else if (t[j] == 'D') {
				for (int k = b[j] + 1; k <= i; ++k)
					mny[k] = max(mny[k], a[j] + 1);
			} else {
				for (int k = i - b[j]; k >= 1; --k)
					mxy[k] = min(mxy[k], a[j] - 1);
			}
		}
		for (int j = 1; j <= i; ++j) {
			flow::AddEdge(1, j + 2 + n * 2, 1, 0);
			flow::AddEdge(j + 2 + n * 2 + i, 2, 1, 0);
		}
		for (int j = 1; j <= n; ++j) {
			flow::AddEdge(j + 2, j + n + 2, 1, -v[j]);
			for (int k = 1; k <= i; ++k) {
				if (x[j] >= mnx[k] && x[j] <= mxx[k]) {
					flow::AddEdge(k + 2 + n * 2, j + 2, 1, 0);
				}
				if (y[j] >= mny[k] && y[j] <= mxy[k]) {
					flow::AddEdge(j + n + 2, k + 2 + n * 2 + i, 1, 0);
				}
			}
		}
		pair<ll, ll> ans = flow::Solve();
		if (ans.first == i) res = max(res, -ans.second);
	}
	printf("%lld", res);
}


Measured memory_bytes: 5120