#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<climits>

typedef long long LL;
const int maxn = 1e5 + 10, maxm = 4e5 + 10;
using namespace std;

LL read()
{
	LL x = 0, f = 1; char c = getchar();
	while(!isdigit(c)) { if(c == '-') f = 0; c = getchar(); }
	while(isdigit(c)) { x = (x << 3) + (x << 1) + (c ^ 48); c = getchar(); }
	return f ? x : -x;
}

int e, s, t, nxt[maxm], head[maxn], cap[maxm], from[maxm], flow[maxm], to[maxm];
int inq[maxn], a[maxn], p[maxn];
LL cost[maxm], d[maxn];

void add(int x, int y, int z, LL w)
{
	to[++e] = y; nxt[e] = head[x]; head[x] = e; cap[e] = z; cost[e] = w; from[e] = x;
	to[++e] = x; nxt[e] = head[y]; head[y] = e; cap[e] = 0; cost[e] = -w; from[e] = y;
}

int spfa()
{
	queue<int> Q;
	Q.push(s); inq[s] = 1; a[s] = 0x3f3f3f3f;
	for(int i = 1; i <= t; ++i) d[i] = -LLONG_MAX;
	d[s] = 0;
	while(!Q.empty())
	{
		int u = Q.front(); Q.pop();
		inq[u] = 0; 
		for(int i = head[u]; i; i = nxt[i])
		{
			int v = to[i];
			if(d[v] < d[u] + cost[i] && cap[i] > flow[i])
			{
				d[v] = d[u] + cost[i]; p[v] = i; a[v] = min(a[u], cap[i] - flow[i]);
 				if(!inq[v]) Q.push(v), inq[v] = 1;
			}
		}
	}
	if(d[t] == -LLONG_MAX) return 0;

	int u = t;
	while(u != s)
	{
		flow[p[u]] += a[u]; flow[p[u] ^ 1] -= a[u];
		u = from[p[u]];
	}
	return 1;
}

LL ans;
void gao(int k)
{
	int Flow = 0; LL C = 0;
	while(spfa()) Flow += a[t], C += d[t] * a[t];
	if(Flow == k) ans = max(ans, C);
}

char S[3];
#define a zjmtaimei
int a[maxn], b[maxn], ty[maxn], x[maxn], y[maxn]; LL v[maxn];
int xz[maxn], hk[maxn];

int main()
{
	int n = read();
	for(int i = 1; i <= n; ++i) x[i] = read(), y[i] = read(), v[i] = read();
	int m = read();
	for(int i = 1; i <= m; ++i) 
	{
		scanf("%s", S);
		ty[i] = S[0]; a[i] = read(); b[i] = read();
	}

	for(int k = 1; k <= n; ++k)
	{
		for(int i = 1; i <= k; ++i) xz[i] = 0, hk[i] = INT_MAX;
		for(int i = 1; i <= m; ++i)
		{
			if(ty[i] == 'L') xz[b[i] + 1] = max(xz[b[i] + 1], a[i] + 1);
			if(k - b[i] > 0 && ty[i] == 'R') hk[k - b[i]] = min(hk[k - b[i]], a[i] - 1);
		}
		for(int i = k - 1; i >= 1; --i) hk[i] = min(hk[i + 1], hk[i]);
		for(int i = 2; i <= k; ++i) xz[i] = max(xz[i], xz[i - 1]);

//		for(int i = 1; i <= k; ++i) cout << xz[i] << ' ' << hk[i] << endl;

		e = 1; memset(head, 0, sizeof(head)); memset(flow, 0, sizeof(flow));
		for(int i = 1; i <= k; ++i)
			for(int j = 1; j <= n; ++j)
				if(xz[i] <= x[j] && x[j] <= hk[i]) add(i, j + k, 1, v[j]);

		for(int i = 1; i <= n; ++i) add(i + k, i + n + k, 1, 0);

		for(int i = 1; i <= k; ++i) xz[i] = 0, hk[i] = INT_MAX;
		for(int i = 1; i <= m; ++i)
		{
			if(ty[i] == 'D') xz[b[i] + 1] = max(xz[b[i] + 1], a[i] + 1);
			if(k - b[i] > 0 && ty[i] == 'U') hk[k - b[i]] = min(hk[k - b[i]], a[i] - 1);
		}
		for(int i = k - 1; i >= 1; --i) hk[i] = min(hk[i + 1], hk[i]);
		for(int i = 2; i <= k; ++i) xz[i] = max(xz[i], xz[i - 1]);

		for(int i = 1; i <= k; ++i)
			for(int j = 1; j <= n; ++j)
				if(xz[i] <= y[j] && y[j] <= hk[i]) add(j + k + n, i + k + n + n, 1, 0);
		s = 2 * k + n * 2 + 1; t = 2 * k + n * 2 + 2;
		for(int i = 1; i <= k; ++i) add(s, i, 1, 0), add(i + k + n + n, t, 1, 0);

		gao(k);
		/*
		for(int u = 1; u <= k; ++u)
		{
			for(int i = head[u]; i; i = nxt[i])
			{
				int v = to[i];
				if(v != s && flow[i] == 1) cout << '*' << u << ' ' << v - k << endl;
			}
		}

		for(int u = 1; u <= k; ++u)
		{
			for(int i = head[u + k + 2 * n]; i; i = nxt[i])
			{
				int v = to[i];
				if(v != t && flow[i] == -1) cout << '*' << u << ' ' << v - n - k << endl;
			}
		}

		for(int i = 1; i <= k; ++i) cout << xz[i] << ' ' << hk[i] << endl;
		*/
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 14592