#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#define mp(a, b) make_pair(a, b)
//#define int long long
using namespace std;
typedef pair<int, long long> pp;
const int maxn = 100100;
const long long oo = 1e17;
const int ioo = 1e9;
struct edges
{
	int to, next, f;
	long long c;
}edge[maxn << 1];
int point[maxn] = {0}, te = 1;
void add(int a, int b, int c, long long d)
{
	te ++;
	edge[te].to = b;
	edge[te].next = point[a];
	edge[te].f = c;
	edge[te].c = d;
	point[a] = te;
}
void adde(int a, int b, int c, long long d)
{
	//cout << a << " " << b << " " << c << " " << d << endl;
	add(a, b, c, d);
	add(b, a, 0, -d);
}
int st = 0, ed = 0;
long long dis[maxn];
queue<int> q;
bool in[maxn];
bool spfa()
{
	for(int i = st; i <= ed; i ++)
		dis[i] = oo;
	dis[st] = 0;
	q.push(st);
	in[st] = 1;
	while(!q.empty())
	{
		int now = q.front();
		q.pop();
		in[now] = 0;
		for(int e = point[now]; e; e = edge[e].next)
			if(edge[e].f && dis[edge[e].to] > dis[now] + edge[e].c)
			{
				dis[edge[e].to] = dis[now] + edge[e].c;
				if(!in[edge[e].to])
				{
					in[edge[e].to] = 1;
					q.push(edge[e].to);
				}
			}
	}
	return dis[ed] < oo;
}
int cur[maxn];
bool flag[maxn] = {0};
pp dfs(int now, int min0)
{
	if(now == ed || min0 == 0)
		return mp(min0, 0);
	flag[now] = 1;
	pp flow;
	flow.first = flow.second = 0;
	for(int &e = cur[now]; e; e = edge[e].next)
		if(edge[e].f && dis[edge[e].to] == dis[now] + edge[e].c && !flag[edge[e].to])
		{
			pp ff = dfs(edge[e].to, min(min0, edge[e].f));
			if(ff.first)
			{
				edge[e].f -= ff.first;
				min0 -= ff.first;
				edge[e ^ 1].f += ff.first;
				flow.first += ff.first;
				flow.second += edge[e].c * ff.first + ff.second;
				if(min0 == 0)
				{
					flag[now] = 0;
					return flow;
				}
			}
		}
	flag[now] = 0;
	return flow;
}
pp sum;
void dinic()
{
	sum.first = sum.second = 0;
	while(spfa())
	{
		for(int i = st; i <= ed; i ++)
			cur[i] = point[i];
		pp a = dfs(st, ioo);
		sum.first += a.first;
		sum.second += a.second;
	}
}
long long ans = 0;
int n, m;
int x[maxn], y[maxn];
long long v[maxn];
struct cons
{
	char t;
	int a, b;
}con[maxn];
int xmn[maxn], xmx[maxn], ymn[maxn], ymx[maxn];
void work(int k)
{
	te = 1;
	for(int i = st; i <= ed; i ++)
		point[i] = 0;
	st = 0, ed = k * 2 + n * 2 + 1;
	for(int i = 1; i <= k; i ++)
		xmx[i] = ymx[i] = ioo;
	for(int i = 1; i <= m; i ++)
	{
		if(con[i].t == 'L' && con[i].b < k)
			xmn[con[i].b + 1] = max(xmn[con[i].b + 1], con[i].a + 1);
		else if(con[i].t == 'R' && con[i].b < k)
			xmx[k - con[i].b] = min(xmx[k - con[i].b], con[i].a - 1);
		else if(con[i].t == 'D' && con[i].b < k)
			ymn[con[i].b + 1] = max(ymn[con[i].b + 1], con[i].a + 1);
		else if(con[i].t == 'U' && con[i].b < k)
			ymx[k - con[i].b] = min(con[i].a - 1, ymx[k - con[i].b]);
	}
	for(int i = 2; i <= k; i ++)
	{
		xmn[i] = max(xmn[i - 1], xmn[i]);
		ymn[i] = max(ymn[i - 1], ymn[i]);
	}
	for(int i = k - 1; i >= 1; i --)
	{
		xmx[i] = min(xmx[i], xmx[i + 1]);
		ymx[i] = min(ymx[i], ymx[i + 1]);
	}
	/*
	for(int i = 1; i <= k; i ++)
		cout << i << " " << xmn[i] << " " << xmx[i] << " " << ymn[i] << " " << ymx[i] << endl;
	*/
	for(int i = 1; i <= k; i ++)
		adde(st, i, 1, 0);
	for(int i = 1; i <= k; i ++)
	{
		for(int j = 1; j <= n; j ++)
			if(xmn[i] <= x[j] && x[j] <= xmx[i])
				adde(i, j + k, 1, 0);
	}
	for(int i = 1; i <= n; i ++)
		adde(i + k, i + n + k, 1, -v[i]);
	for(int i = 1; i <= k; i ++)
	{
		for(int j = 1; j <= n; j ++)
			if(ymn[i] <= y[j] && y[j] <= ymx[i])
				adde(j + n + k, i + n + k + n, 1, 0);
	}
	for(int i = 1; i <= k; i ++)
		adde(i + n + n + k, ed, 1, 0);
	dinic();
	//cout << sum.first << endl;
	if(sum.first == k)
		ans = max(ans, -sum.second);
}
signed main()
{
	std::ios::sync_with_stdio(false);
	cin >> n;
	for(int i = 1; i <= n; i ++)
		cin >> x[i] >> y[i] >> v[i];
	cin >> m;
	for(int i = 1; i <= m; i ++)
		cin >> con[i].t >> con[i].a >> con[i].b;
	st = 0;
	//work(3);
	
	for(int k = 1; k <= n; k ++)
		work(k);
		
	cout << ans << endl;
	return 0;
}
/*
4
1 6 6
1 2 2
9 3 9
6 4 4
4
D 10 1
L 8 2
D 1 1
R 4 1
*/

Measured memory_bytes: 6400