#include <bits/stdc++.h>
using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os<<"{";
	rep(i, v.size()) {
		if (i) os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

#define MN 510
const ll INF = TEN(18);

struct edge {
	int to, cap, rev; ll cost;
	edge(int to, int cap, ll cost, int rev) : to(to), cap(cap), cost(cost), rev(rev){}
};

int N;
vector<edge> g[MN];
ll h[MN], dst[MN];
int prevv[MN], preve[MN];

inline void add_edge(int f, int t, int cap, ll cost) {
	g[f].emplace_back(t, cap, cost, (int)g[t].size());
	g[t].emplace_back(f, 0, -cost, (int)g[f].size() - 1);
}

ll min_cost_flow(int s, int t, int f) {
	ll res = 0;
	memset(h, 0, sizeof(h));
/*
	fill(h, h + N + 1, INF);
	h[s] = 0;
	for (int t = 0; t < N; ++t) {
		for (int i = 0; i < N; ++i) {
			for (auto e : g[i]) if (e.cap) {
				h[e.to] = min(h[e.to], h[i] + e.cost);
			}
		}
	}
*/
	while (f > 0) {
		using pli = pair<ll, int>;
		priority_queue<pli, vector<pli>, greater<pli> > que;
		fill(dst, dst + N + 1, INF);
		dst[s] = 0;
		que.push(mp(0, s));
		while (!que.empty()) {
			pli p = que.top(); que.pop();
			int v = p.se;
			if (dst[v] < p.fi) continue;
			rep(i, g[v].size()) {
				edge &e = g[v][i];
				ll nd = dst[v] + e.cost + h[v] - h[e.to];
				if (e.cap > 0 && dst[e.to] > nd) {
					dst[e.to] = nd;
					prevv[e.to] = v;
					preve[e.to] = i;
					que.push(mp(dst[e.to], e.to));
				}
			}
		}

		if (dst[t] == INF) return -INF;
		rep(i, N) h[i] += dst[i];

		int d = f;
		for (int v = t; v != s; v = prevv[v]) {
			d = min(d, g[prevv[v]][preve[v]].cap);
		}
		f -= d;
		res += d * h[t];
		for (int v = t; v != s; v = prevv[v]) {
			edge &e = g[prevv[v]][preve[v]];
			e.cap -= d;
			g[v][e.rev].cap += d;
		}
	}

	return res;
}

int main() {
	int n; cin >> n;
	vector<pair<pii, ll>> pts(n);

	rep(i, n) {
		int x, y; ll v;
		cin >> x >> y >> v;
		--x; --y;
		pts[i] = mp(mp(x, y), v);
	}

	int M; cin >> M;
	vector<pair<int, pii>> conds;
	rep(i, M) {
		char c; int a, b;
		cin >> c >> a >> b;
		--a; 
		if (c == 'L') {
			conds.eb(0, mp(a, b));
		} else if (c == 'R') {
			conds.eb(1, mp(a, b));
		} else if (c == 'D') {
			conds.eb(2, mp(a, b));
		} else {
			conds.eb(3, mp(a, b));
		}
	}

	ll ans = 0;

	for (int num = 1; num <= n; ++num) {
		rep(j, MN) g[j].clear();
		vi lox(num + 1, 0), hix(num + 1, 99), loy(num + 1, 0), hiy(num + 1, 99);

		rep(i, M) {
			int a = conds[i].se.fi, b = conds[i].se.se;
			if (b >= num) continue;

			if (conds[i].fi == 0) {
				lox[b + 1] = max(lox[b + 1], a + 1);
			} else if (conds[i].fi == 1) {
				hix[num - b] = min(hix[num - b], a - 1);
			} else if (conds[i].fi == 2) {
				loy[b + 1] = max(loy[b + 1], a + 1);
			} else {
				hiy[num - b] = min(hiy[num - b], a - 1);
			}
		}

		bool ok = true;
		for (int i = 1; i <= num; ++i) {
			if (lox[i] > hix[i] || loy[i] > hiy[i]) {
				ok = false;
			}
		}

		if (!ok) continue;
		rep(i, num) {
			lox[i+1] = max(lox[i+1], lox[i]);
			loy[i+1] = max(loy[i+1], loy[i]);
		}
		for (int i = num-1; i >= 0; --i) {
			hix[i] = min(hix[i], hix[i+1]);
			hiy[i] = min(hiy[i], hiy[i+1]);
		}

		N = (1 + num + 100) * 2;

		int s = 0, t = N-1;

		rep(i, num) {
			add_edge(s, i + 1, 1, 0ll);
			for (int x = lox[i+1]; x <= hix[i+1]; ++x) {
				add_edge(i + 1, 1 + num + x, 1, 0ll);
			}

			add_edge(1 + num + 100 + 100 + i, t, 1, 0ll);
			for (int y = loy[i+1]; y <= hiy[i+1]; ++y) {
				add_edge(1 + num + 100 + y, 1 + num + 100 + 100 + i, 1, 0ll);
			}
		}

		rep(i, n) {
			int x = pts[i].fi.fi, y = pts[i].fi.se;
			add_edge(1 + num + x, 1 + num + 100 + y, 1, -pts[i].se);
		}

		ll res = min_cost_flow(s, t, num);
		if (res != -INF) {
			ans = max(ans, -res);
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1280