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

using namespace std;
const int INF(0X3F3F3F3F);
typedef long long int LL;

namespace G
{
	const int Max_V(85 * 2);
	const int Max_E(85 * 30);
	int V, S, T, Head[Max_V], Total, To[Max_E], Next[Max_E], Cap[Max_E], Flow[Max_E];
	LL Weight[Max_E];
	void clear()
	{
		for (int i = 1;i <= V;++i)
			Head[i] = 0;
		for (int i = 2;i <= Total + 1;++i)
			To[i] = Next[i] = Cap[i] = Flow[i] = Weight[i] = 0;
		V = S = T = Total = 0;
	}
	inline void Add_Edge(int tot, int s, int t, int c, LL w)
	{
		To[tot] = t, Next[tot] = Head[s], Head[s] = tot, Cap[tot] = c, Flow[tot] = 0, Weight[tot] = w;
	}
	inline void Add_Link(int s, int t, int c, LL w)
	{
		Total += 2, Add_Edge(Total, s, t, c, w), Add_Edge(Total ^ 1, t, s, 0, -w);
	}
	LL Dist[Max_V];
	bool InQ[Max_V], done[Max_V];
	bool SPFA()
	{
		queue<int> Q;
		memset(Dist, -0X3F, sizeof(Dist)), Dist[S] = 0LL;
		memset(done, false, sizeof(done)), Q.push(S), InQ[S] = true;
		for (int u;Q.empty() == false;)
		{
			u = Q.front(), Q.pop(), InQ[u] = false, done[u] = true;
			for (int i = Head[u], v;i;i = Next[i])
				if (Cap[i] > Flow[i] && Dist[v = To[i]] < Dist[u] + Weight[i])
				{
					Dist[v] = Dist[u] + Weight[i];
					if (!InQ[v])
						Q.push(v), InQ[v] = true;
				}
		}
		return done[T];
	}
	int Cur[Max_V];
	int DFS(int u, int a)
	{
		if (u == T || a == 0)
			return a;
		int Ans(0);
		done[u] = true;
		for (int &i = Cur[u], v, f;i;i = Next[i])
			if (Dist[v = To[i]] == Dist[u] + Weight[i] && !done[v] && (f = DFS(v, min(a, Cap[i] - Flow[i]))) > 0)
			{
				Ans += f, Flow[i] += f, Flow[i ^ 1] -= f;
				if ((a -= f) == 0)
					break;
			}
		done[u] = false;
		return Ans;
	}
	void MCMF(int &FLOW, LL &COST)
	{
		for (int f;SPFA();)
		{
			for (int i = 1;i <= V;++i)
				Cur[i] = Head[i], done[i] = false;
			FLOW -= (f = DFS(S, INF)), COST += Dist[T] * f;
		}
	}
}

const int Max_N(85);
const int Max_M(325);

int N, X[Max_N], Y[Max_N], PX[Max_N], PY[Max_N], XL[Max_N], XR[Max_N], YL[Max_N], YR[Max_N], M, T[Max_M], A[Max_M], B[Max_M];
LL V[Max_N], Ans;

inline bool comp_X(int a, int b)
{
	return X[a] < X[b];
}

inline bool comp_Y(int a, int b)
{
	return Y[a] < Y[b];
}

/*
枚举选的宝石总数Sum，那么可以变成对于每个前缀选的宝石数量都有一个区间的限制。在X轴和Y轴上分别可以列出方程
X轴的方程组： 
0 = 0
X[1] = XV[1]
X[1] + X[2] = XV[2]
...
X[1] + X[2] + ... + X[N] = Sum
Y轴的方程组： 
0 = 0
Y[1] = YV[1]
Y[1] + Y[2] = YV[2]
...
Y[1] + Y[2] + ... + Y[N] = Sum
对于每个XV[i]，有XL[i] <= XV[i] <= XR[i]的限制；对于每个YV[i]，有YL[i] <= YV[i] <= YR[i]的限制
对于每个轴的方程组，两两差分。那么每个XV和YV出现了恰好两次，系数分别是+1和-1。每个X和Y出现了恰好一次
那么对于点(x, y)，X[x]和Y[y]是同一个变量。所以这些变量可以看做出现了恰好两次，系数分别是+1和-1
然后用流量平衡建图，可以得到一个最大费用可行流问题 
*/
int main()
{
	scanf("%d", &N);
	for (int i = 1;i <= N;++i)
		scanf("%d%d%lld", X + i, Y + i, V + i), PX[i] = PY[i] = i;
	sort(PX + 1, PX + 1 + N, comp_X), sort(PY + 1, PY + 1 + N, comp_Y);
	scanf("%d", &M);
	for (int i = 1;i <= M;++i)
	{
		char op[10];
		scanf("%s%d%d", op, A + i, B + i);
		if (*op == 'L')
			T[i] = 1;
		if (*op == 'R')
			T[i] = 2;
		if (*op == 'D')
			T[i] = 3;
		if (*op == 'U')
			T[i] = 4;
	}
	for (int Sum = 1;Sum <= N;++Sum)
	{
		XL[0] = YL[0] = XR[0] = YR[0] = 0;
		for (int i = 1;i <= N - 1;++i)
			XL[i] = YL[i] = 0, XR[i] = YR[i] = Sum;
		XL[N] = YL[N] = XR[N] = YR[N] = Sum;
		for (int i = 1;i <= M;++i)
		{
			if (T[i] == 1)
				if (X[PX[1]] <= A[i])
					for (int j = 1;j <= N;++j)
						if (j == N || X[PX[j + 1]] > A[i])
						{
							XR[j] = min(XR[j], B[i]);
							break;
						}
			if (T[i] == 2)
				if (A[i] <= X[PX[N]])
					for (int j = N - 1;j >= 0;--j)
						if (j == 0 || A[i] > X[PX[j]])
						{
							XL[j] = max(XL[j], Sum - B[i]);
							break;
						}
			if (T[i] == 3)
				if (Y[PY[1]] <= A[i])
					for (int j = 1;j <= N;++j)
						if (j == N || Y[PY[j + 1]] > A[i])
						{
							YR[j] = min(YR[j], B[i]);
							break;
						}
			if (T[i] == 4)
				if (A[i] <= Y[PY[N]])
					for (int j = N - 1;j >= 0;--j)
						if (j == 0 || A[i] > Y[PY[j]])
						{
							YL[j] = max(YL[j], Sum - B[i]);
							break;
						}
		}
		for (int i = 0;i <= N;++i)
			if (XL[i] > XR[i] || YL[i] > YR[i])
				goto loop;
		int FLOW(0);
		LL COST(0LL);
		G::clear(), G::V = N + N + 2, G::S = N + N + 1, G::T = N + N + 2;
		for (int i = 1, x, y;i <= N;++i)
		{
			for (x = 1;x <= N;++x)
				if (PX[x] == i)
					break;
			for (y = 1;y <= N;++y)
				if (PY[y] == i)
					break;
			COST += V[i], ++FLOW, G::Add_Link(G::S, x, 1, 0LL), G::Add_Link(N + y, G::T, 1, 0LL);
			G::Add_Link(x, N + y, 1, -V[i]);
		}
		for (int i = 1;i <= N - 1;++i)
		{
			if (XL[i])
				G::Add_Link(G::S, i + 1, XL[i], 0LL), G::Add_Link(i, G::T, XL[i], 0LL), FLOW += XL[i];
			if (XR[i] - XL[i])
				G::Add_Link(i, i + 1, XR[i] - XL[i], 0LL);
		}
		for (int i = 1;i <= N - 1;++i)
		{
			if (YL[i])
				G::Add_Link(G::S, N + i, YL[i], 0LL), G::Add_Link(N + (i + 1), G::T, YL[i], 0LL), FLOW += YL[i];
			if (YR[i] - YL[i])
				G::Add_Link(N + (i + 1), N + i, YR[i] - YL[i], 0LL);
		}
		FLOW += Sum, G::Add_Link(N, G::T, Sum, 0LL), G::Add_Link(G::S, N + N, Sum, 0LL);
		G::MCMF(FLOW, COST);
		if (FLOW)
			goto loop;
		Ans = max(Ans, COST);
	}
	loop :
	printf("%lld", Ans);
	return 0;
}

Measured memory_bytes: 256