#include <algorithm>
// #include <cstdlib>
#include <cstring>
#include <cstdio>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <bitset>
using namespace std;
typedef long long LL;
typedef double db;
const int oo=2139063143;
const int N=410;
const int P=1000000007;
const db eps=1e-7;
#define pritnf printf
//char buf[1<<22],*p1=buf,*p2=buf,obuf[1<<22],*O=obuf;
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
template <typename T>
inline void sc (T &x)
{
    x=0; static int p; p=1; static char c; c=getchar();
    while (!isdigit(c)) { if (c=='-') p=-1; c=getchar(); }
    while ( isdigit(c)) { x=(x<<1)+(x<<3)+(c-48); c=getchar(); }
    x*=p;
}
template <typename T>
inline void print (T x)
{
    if (x< 0) putchar('-'),x=-x;
    if (x>=10) print(x/10);
    putchar(x%10+'0');
}
template <typename T>
inline void pr (T x) { print(x),putchar('\n'); }
template <typename T1,typename T2>
void chkmax (T1 &A,T2 B) { A=A>=B?A:B; }
template <typename T1,typename T2>
void chkmin (T1 &A,T2 B) { A=A<=B?A:B; }
struct EDGE { int v,w; LL c; int nx; }lb[N*N<<3]; int tot=1,top[N];
void add (int u,int v,int w,LL c)
{
	lb[++tot]=(EDGE){v,w, c,top[u]},top[u]=tot;
	lb[++tot]=(EDGE){u,0,-c,top[v]},top[v]=tot;
}
int s,t;
LL dis[N]; int flow[N],pre[N],las[N]; bool in[N];
bool spfa ()
{
	for (int i=1; i<=t; i++)
		dis[i]=-1e18,flow[i]=pre[i]=las[i]=0,in[i]=0;
	queue <int> q;
	flow[s]=oo,dis[s]=0,q.push (s),in[s]=1;
	while (q.size ())
	{
		int u=q.front (); q.pop (); in[u]=0;
		for (int kb=top[u]; kb; kb=lb[kb].nx)
		{
			int v=lb[kb].v,w=lb[kb].w; LL c=lb[kb].c;
			if (w&&dis[v]< dis[u]+c)
			{
				dis[v]=dis[u]+c;
				flow[v]=min (flow[u],w);
				pre[v]=u,las[v]=kb;
				if (!in[v]) q.push (v),in[v]=1;
			}
		}
	}
	return pre[t];
}
int maflow; LL macost;
void mcmf ()
{
	while (spfa ())
	{
		int u=t,fl=flow[t]; maflow+=fl,macost+=dis[t]*fl;
		while (u!=s)
		{
			lb[las[u]].w-=fl,lb[las[u]^1].w+=fl;
			u=pre[u];
		}
	}
}
int n,m;
struct LY { int x,y; LL w; }p[N];
int op[N],a[N],b[N],L[N],R[N];
LL solve (int k)
{
	s=(n+k)*2+1,t=s+1;
	memset (top,0,sizeof (int)*(t+1)),tot=1;
	for (int i=1; i<=n; i++)
		add (i,i+n,1,p[i].w);
	for (int i=1; i<=k; i++)
		add (s,n*2+i,1,0),add (n*2+k+i,t,1,0);
	memset (L,0,sizeof (int)*(k+2)),memset (R,127,sizeof (int)*(k+2));
	for (int i=1; i<=m; i++) if (b[i]<=k)
	{
		if (op[i]==1) chkmax (L[b[i]+1],a[i]+1);
		else if (op[i]==2) chkmin (R[k-b[i]],a[i]-1);
	}
	for (int i=2; i<=k; i++)
		chkmax (L[i],L[i-1]);
	for (int i=k-1; i>=1; i--)
		chkmin (R[i],R[i+1]);
	for (int i=1; i<=n; i++)
		for (int j=1; j<=k; j++) if (L[j]<=p[i].x&&p[i].x<=R[j])
			add (n*2+j,i,1,0);
	memset (L,0,sizeof (int)*(k+2)),memset (R,127,sizeof (int)*(k+2));
	for (int i=1; i<=m; i++) if (b[i]<=k)
	{
		if (op[i]==3) chkmax (L[b[i]+1],a[i]+1);
		else if (op[i]==4) chkmin (R[k-b[i]],a[i]-1);
	}
	for (int i=2; i<=k; i++)
		chkmax (L[i],L[i-1]);
	for (int i=k-1; i>=1; i--)
		chkmin (R[i],R[i+1]);
	for (int i=1; i<=n; i++)
		for (int j=1; j<=k; j++) if (L[j]<=p[i].y&&p[i].y<=R[j])
			add (n+i,n*2+k+j,1,0);
	maflow=macost=0;
	mcmf ();
	return maflow< k?-1:macost;
}
int main ()
{
    // freopen (".in","r",stdin);
    // freopen (".out","w",stdout);
	sc(n);
	for (int i=1; i<=n; i++)
		sc(p[i].x),sc(p[i].y),sc(p[i].w);
	sc(m);
	for (int i=1; i<=m; i++)
	{
		char s[2]; scanf ("%s",s);
		sc(a[i]),sc(b[i]);
		if (s[0]=='L') op[i]=1;
		else if (s[0]=='R') op[i]=2;
		else if (s[0]=='D') op[i]=3;
		else op[i]=4;
	}
	LL ans=0;
	for (int i=1; i<=n; i++)
	{
		LL g=solve (i);
		if (g==-1) break;
		chkmax (ans,g);
	}
	pr(ans);


    return 0;
}

Measured memory_bytes: 640