#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin (),(x).end()
#define sqrt(x) sqrt(abs(x))
#define re return
#define sz(x) ((int)(x).size ())
#define prev PREV
#define next NEXT

using ll = long long;
using ii = pair<int, int>;
using ld = long double;
using D = double;
using vi = vector<int>;
using vii = vector<ii>;
using vvi = vector<vi>;
using vs = vector<string>;

template<typename T> T abs (T x) { re x < 0 ? -x : x; }
template<typename T> T sgn (T x) { re x < 0 ? -1 : (x > 0 ? 1 : 0); }
template<typename T> T sqr (T x) { re x * x; }
template<typename T> T gcd (T a, T b) { re a != 0 ? gcd (b % a, a) : b; }

const int inf = 1e9;
const ll INF = 1e15;

int n;
int m;
int o, e;
int x[200];
int y[200];
ll val[200];
int a[400];
int b[400];
string t[400];
vi vx, vy;
int lx[200];
int rx[200];
int ly[200];
int ry[200];

vii v[2000];
int ec[200000];
ll ef[200000];
ll d[2000];
ll p[2000];
int mark[2000];
int prev[2000];
int preve[2000];
set<pair<ll, int> > all;


void addedge (int a, int b, int c, ll d) {
//	printf ("%d %d %d %I64d\n", a, b, c, d);
	v[a].pb (mp (b, e));
	ec[e] = c;
	ef[e] = d;
	e++;
	v[b].pb (mp (a, e));
	ec[e] = 0;
	ef[e] = -d;
	e++;
}

ll go (int S, int T) {
	all.clear ();
	for (int i = 0; i < o; i++) {
		mark[i] = 0;
		d[i] = 1e18;
	}
	mark[S] = 1;
	d[S] = 0;
	all.insert (mp (0, S));
	while (!all.empty ()) {
		int x = all.begin ()->se;
//		printf ("%d\n", x);
		mark[x] = 2;
		all.erase (all.begin ());
		for (int i = 0; i < sz (v[x]); i++) {
			int y = v[x][i].fi;
			int z = v[x][i].se;
			if (ec[z] > 0 && d[x] + p[x] + ef[z] - p[y] < d[y]) {
				if (mark[y] == 1) all.erase (mp (d[y], y));
				d[y] = d[x] + p[x] + ef[z] - p[y];
				prev[y] = x;
				preve[y] = z;
				mark[y] = 1;
				all.insert (mp (d[y], y));
			}
		}
	}
	if (mark[T] == 0) re -1;
	ll ans = d[T] - p[S] + p[T];
	for (int i = 0; i < o; i++)
		if (mark[i])
			p[i] += d[i];
	re ans;
}

map<int, ll> was;

ll calc (int h) {
	if (was.count (h)) re was[h];
	int ox = sz (vx);
	int oy = sz (vy);
	for (int i = 0; i < ox; i++) {
		lx[i] = 0;
		rx[i] = h;
		for (int j = 0; j < m; j++)
			if (t[j] == "L") {
				if (vx[i] <= a[j]) rx[i] = min (rx[i], b[j]);
			} else
			if (t[j] == "R") {
				if (vx[i] >= a[j] - 1) lx[i] = max (lx[i], h - b[j]);
			}
		if (lx[i] > rx[i]) re was[h] = -1;	
	}
	for (int i = 0; i < oy; i++) {
		ly[i] = 0;
		ry[i] = h;
		for (int j = 0; j < m; j++)
			if (t[j] == "D") {
				if (vy[i] <= a[j]) ry[i] = min (ry[i], b[j]);
			} else
			if (t[j] == "U") {
				if (vy[i] >= a[j] - 1) ly[i] = max (ly[i], h - b[j]);
			}
		if (ly[i] > ry[i]) re was[h] = -1;	
	}
	o = 2 * ox + 2 * oy + 2 * n + 5;
	e = 0;
	for (int i = 0; i < o; i++) v[i].clear ();
	int req = 0;
	addedge (o - 4, 2 * n + 2 * (ox - 1), inf, 0);
	for (int i = 0; i < ox; i++) {
//		printf ("x %d: %d %d\n", vx[i], lx[i], rx[i]);
		req += lx[i];
		addedge (2 * n + 2 * i, 2 * n + 2 * i + 1, rx[i] - lx[i], 0);
		addedge (o - 2, 2 * n + 2 * i + 1, lx[i], 0);
		addedge (2 * n + 2 * i, o - 1, lx[i], 0);
		if (i > 0) addedge (2 * n + 2 * i + 1, 2 * n + 2 * (i - 1), inf, 0);
	}
	addedge (2 * n + 2 * ox + 2 * (oy - 1) + 1, o - 3, inf, 0);
	for (int i = 0; i < oy; i++) {
//		printf ("y %d: %d %d\n", vy[i], ly[i], ry[i]);
		req += ly[i];
		addedge (2 * n + 2 * ox + 2 * i, 2 * n + 2 * ox + 2 * i + 1, ry[i] - ly[i], 0);
		addedge (o - 2, 2 * n + 2 * ox + 2 * i + 1, ly[i], 0);
		addedge (2 * n + 2 * ox + 2 * i, o - 1, ly[i], 0);
		if (i > 0) addedge (2 * n + 2 * ox + 2 * (i - 1) + 1, 2 * n + 2 * ox + 2 * i, inf, 0);
	}
	for (int i = 0; i < n; i++) {
		addedge (2 * i, 2 * i + 1, 1, INF - val[i]);
		int j = 0;
		while (vx[j] < x[i]) j++;
		addedge (2 * n + 2 * j + 1, 2 * i, inf, 0);
		j = 0;
		while (vy[j] < y[i]) j++;
		addedge (2 * i + 1, 2 * n + 2 * ox + 2 * j, inf, 0);
	}
	req += h;
	addedge (o - 3, o - 5, inf, 0);
	addedge (o - 2, o - 4, h, 0);
	addedge (o - 5, o - 1, h, 0);
	ll ans = 0;
	for (int i = 0; i < o; i++) p[i] = 0;
	for (int i = 0; i < req; i++) {
		ll tmp = go (o - 2, o - 1);
//		printf ("%d: %d = %I64d\n", h, i, INF - tmp);
		if (tmp == -1) re was[h] = -1;
		ans += tmp;
		int j = o - 1;
		while (j != o - 2) {
			int k = prev[j];
			int z = preve[j];
			ec[z]--;
			ec[z ^ 1]++;
//			printf ("%d -> %d = %d\n", k / 2, j / 2, ec[z]);
			j = k;
		}
	}
	ll tmp = go (o - 2, o - 1);
	re was[h] = h * INF - ans;
}

int main () {
	cin >> n;
	for (int i = 0; i < 100; i++) {
		vx.pb (i + 1);
		vy.pb (i + 1);
	}
	for (int i = 0; i < n; i++) {
		cin >> x[i] >> y[i] >> val[i];
		vx.pb (x[i]);
		vy.pb (y[i]);
	}	
	cin >> m;
	for (int i = 0; i < m; i++) {
		cin >> t[i] >> a[i] >> b[i];
		if (t[i] == "L" || t[i] == "R") vx.pb (a[i]); else vy.pb (a[i]);
	}
	sort (all (vx));
	vx.resize (unique (all (vx)) - vx.begin ());
	sort (all (vy));
	vy.resize (unique (all (vy)) - vy.begin ());
	ll ans = 0;
	int l = 0, r = n;
	while (r - l > 2) {
		int s1 = (2 * l + r) / 3;
		int s2 = (l + 2 * r) / 3;
		ll h1 = calc (s1);
		ll h2 = calc (s2);
		if (h1 >= h2) r = s2; else l = s1;
	}
	for (int i = l; i <= r; i++) ans = max (ans, calc (i));
/*	for (int t = 0; t <= n; t++) {
		ll tmp = calc (t);
		ans = max (ans, tmp);
	}	*/
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384