#include <algorithm>
#include <cstring>
#include <cstdio>
using ll = long long;
int lst[405], to[200005], pre[200005], cap[200005], tot;
int que[2000005], path[405], sum[405];
bool in[405], vis[405];
ll dis[405], cost[200005];
inline void add_edge(int u, int v, int _cap, ll _cost)
{
	auto _add = [&] (int x, int y, int ca, ll co)
	{
		to[tot] = y;
		pre[tot] = lst[x];
		cap[tot] = ca;
		cost[tot] = co;
		lst[x] = tot++;
	};
	_add(u, v, _cap, _cost);
	_add(v, u, 0, -_cost);
}
int dfs(int u, int t, int rem)
{
	if (u == t)
		return rem;
	vis[u] = true;
	int ans = 0;
	for (int i = lst[u]; ~i; i = pre[i])
	{
		if (vis[to[i]] || !cap[i] || dis[to[i]] != dis[u] + cost[i])
			continue;
		int v = to[i], res = dfs(v, t, std::min(rem - ans, cap[i]));
		cap[i] -= res;
		cap[i ^ 1] += res;
		ans += res;
		if (ans == rem)
			return ans;
	}
	return ans;
}
inline ll min_cost_max_flow(int s, int t)
{
	ll res = 0;
	while (true)
	{
		memset(dis, 0x3f, sizeof(dis));
		memset(in, false, sizeof(in));
		int he = 0, ta = 0;
		que[ta++] = s;
		dis[s] = 0;
		in[s] = true;
		auto update = [&] { if (he < ta && dis[que[he]] > dis[que[ta - 1]]) std::swap(que[he], que[ta - 1]); };
	while (he < ta)
		{
			int u = que[he++];
			in[u] = false;
			update();
			for (int i = lst[u]; ~i; i = pre[i])
			{
				if (cap[i] && dis[to[i]] > dis[u] + cost[i])
				{
					path[to[i]] = i;
					dis[to[i]] = dis[u] + cost[i];
					if (!in[to[i]])
					{
						in[to[i]] = true;
						que[ta++] = to[i];
						update();
					}
				}
			}
		}
		if (dis[t] >= 1e18)
			break;
		while (true)
		{
			for (int i = 0; i < ta; i++)
				vis[que[i]] = false;
			int mn = dfs(s, t, 1e9);
			if (!mn)
				break;
			res += mn * dis[t];
		}
	}
	return res;
}
constexpr int LIM = 100;
struct { int x, y; ll w; } arr[405];
struct { char tp; int a, b; } qry[405];
int xl[405], xr[405], yl[405], yr[405];
int main()
{
	// freopen("AGC031-E.in", "r", stdin);
	int n, q;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%d%d%lld", &arr[i].x, &arr[i].y, &arr[i].w);
	scanf("%d", &q);
	for (int i = 0; i < q; i++)
		scanf(" %c%d%d", &qry[i].tp, &qry[i].a, &qry[i].b);
	ll ans = 0;
	for (int k = 1; k <= n; k++)
	{
		for (int i = 1; i <= k; i++)
		{
			xl[i] = yl[i] = 0;
			xr[i] = yr[i] = LIM;
		}
		for (int i = 0; i < q; i++)
		{
			if (qry[i].b >= k)
				continue;
			if (qry[i].tp == 'L' || qry[i].tp == 'D')
			{
				int *res = qry[i].tp == 'L' ? xl : yl;
				res[qry[i].b + 1] = std::max(res[qry[i].b + 1], qry[i].a + 1);
			}
			else
			{
				int *res = qry[i].tp == 'R' ? xr : yr;
				res[k - qry[i].b] = std::min(res[k - qry[i].b], qry[i].a - 1);
			}
		}
		for (int i = 2; i <= k; i++)
		{
			xl[i] = std::max(xl[i], xl[i - 1]);
			yl[i] = std::max(yl[i], yl[i - 1]);
		}
		for (int i = k - 1; i; i--)
		{
			xr[i] = std::min(xr[i], xr[i + 1]);
			yr[i] = std::min(yr[i], yr[i + 1]);
		}
		memset(lst, -1, sizeof(lst));
		tot = 0;
		for (int i = 1; i <= k; i++)
		{
			add_edge(0, i, 1, 0);
			add_edge(k + i, k * 2 + LIM * 2 + 1, 1, 0);
			for (int j = xl[i]; j <= xr[i]; j++)
				add_edge(i, k * 2 + j, 1, 0);
			for (int j = yl[i]; j <= yr[i]; j++)
				add_edge(k * 2 + LIM + j, k + i, 1, 0);
		}
		for (int i = 0; i < n; i++)
			add_edge(k * 2 + arr[i].x, k * 2 + LIM + arr[i].y, 1, -arr[i].w);
		ans = std::max(ans, -min_cost_max_flow(0, k * 2 + LIM * 2 + 1));
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 2560