#include<bits/stdc++.h>
#define maxn 400
#define N 500
#define M 100000
#define T 1000000
#define ll long long
#define INF 1000000000000000000LL
using namespace std;
int tx[maxn], ty[maxn], id1[maxn], id2[maxn], s = 1, t = 2, cnt = 2, n, m, edge = 1;
int head[N], nxt[M], a[M], r[M], dl[T], L[2][maxn], R[2][maxn], c1[maxn], c2[maxn];
ll cost[M], dis[N], val[maxn], res, sum, cur[N], visit[N], id3[2][maxn];
char tp[maxn];
void create(int u, int v, int rest, ll money)
{
	edge++; a[edge] = v; nxt[edge] = head[u]; head[u] = edge;
	r[edge] = rest; cost[edge] = money;
}
void build()
{
	int lef = 1, righ = 1;
	dl[1] = s;
	for (int i = 1; i <= cnt; i++)
	{
		dis[i] = -INF;
		cur[i] = head[i];
	}
	dis[s] = 0; visit[s] = 1;
	while (lef <= righ)
	{
		int u = dl[lef];
		for (int i = head[u]; i; i = nxt[i])
		{
			int v = a[i];
			if (r[i] && dis[u] + cost[i] > dis[v])
			{
				dis[v] = dis[u] + cost[i];
				if (visit[v] == 0) {visit[v] = 1; dl[++righ] = v;}
			}
		}
		lef++; visit[u] = 0;
	}
}
int dinic(int u, int flow)
{
	if (u == t) {sum += flow * dis[t]; return flow;}
	int ans = 0;
	visit[u] = 1;
	for (int i = cur[u]; i; i = nxt[i])
	{
		int v = a[i];
		cur[u] = i;
		if (r[i] && dis[u] + cost[i] == dis[v] && visit[v] == 0)
		{
			int low = dinic(v, min(flow, r[i]));
			r[i] -= low; r[i ^ 1] += low;
			flow -= low; ans += low;
			if (flow == 0) break;
		}
	}
	visit[u] = 0;
	if (ans == 0) dis[u] = -INF;
	return ans;
}
void check(int x)
{
	for (int i = 1; i <= x; i++)
	{
		L[0][i] = L[1][i] = 0;
		R[0][i] = R[1][i] = 110;
	}
	for (int i = 1; i <= m; i++)
		if (tp[i] == 'L' && c2[i] < x) L[0][c2[i] + 1] = c1[i] + 1;
		else if (tp[i] == 'R' && c2[i] < x) R[0][x - c2[i]] = c1[i] - 1;
		else if (tp[i] == 'D' && c2[i] < x) L[1][c2[i] + 1] = c1[i] + 1;
		else if (tp[i] == 'U' && c2[i] < x) R[1][x - c2[i]] = c1[i] - 1;
	for (int i = 2; i <= x; i++)
	{
		L[0][i] = max(L[0][i], L[0][i - 1]);
		L[1][i] = max(L[1][i], L[1][i - 1]);
	}
	for (int i = x - 1; i >= 1; i--)
	{
		R[0][i] = min(R[0][i], R[0][i + 1]);
		R[1][i] = min(R[1][i], R[1][i + 1]);
	}
	for (int i = 1; i <= x; i++)
	{
		create(s, id1[i], 1, 0);
		create(id1[i], s, 0, 0);
	}
	for (int i = 1; i <= x; i++)
	{
		create(id2[i], t, 1, 0);
		create(t, id2[i], 0, 0);
	}
	for (int i = 1; i <= n; i++)
	{
		create(id3[0][i], id3[1][i], 1, val[i]);
		create(id3[1][i], id3[0][i], 0, -val[i]);
		for (int j = 1; j <= x; j++)
		{
			if (tx[i] >= L[0][j] && tx[i] <= R[0][j])
			{
				create(id1[j], id3[0][i], 1, 0);
				create(id3[0][i], id1[j], 0, 0);
			}
			if (ty[i] >= L[1][j] && ty[i] <= R[1][j])
			{
				create(id3[1][i], id2[j], 1, 0);
				create(id2[j], id3[1][i], 0, 0);
			}
		}
	}
	build();
	int mxflow = 0;
	sum = 0;
	while (dis[t] != -INF)
	{
		mxflow += dinic(s, 2e9);
		build();
	}
	if (mxflow == x) res = max(res, sum);
	edge = 1;
	for (int i = 1; i <= cnt; i++)
		head[i] = 0;
}
int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
	{
		scanf("%d%d%lld", &tx[i], &ty[i], &val[i]);
		id1[i] = ++cnt; id2[i] = ++cnt;
		id3[0][i] = ++cnt; id3[1][i] = ++cnt;
	}
	scanf("%d", &m);
	for (int i = 1; i <= m; i++)
	{
		char c = getchar();
		while (c < 'A' || c > 'Z') c = getchar();
		scanf("%d%d", &c1[i], &c2[i]);
		tp[i] = c;
	}
	for (int i = 1; i <= n; i++)
		check(i);
	printf("%lld\n", res);
	return 0;
}

Measured memory_bytes: 640