#include<bits/stdc++.h>
#define llong long long
#define mkpr make_pair
#define pii pair<int,int>
#define riterator reverse_iterator
using namespace std;

inline int read()
{
	int x = 0,f = 1; char ch = getchar();
	for(;!isdigit(ch);ch=getchar()) {if(ch=='-') f = -1;}
	for(; isdigit(ch);ch=getchar()) {x = x*10+ch-48;}
	return x*f;
}



namespace NetFlow
{
	const int N = 206;
	const int M = 284;
	#define lllong __int128
	const lllong INF = 2e17;
	const lllong INF2 = 1e22;
void write_lll(lllong x)
{
	int outputbuf[50]; int len=0; if(x<0) {printf("-"); x = -x;}
	while(x) {outputbuf[len++] = x%10; x/=10;}
	for(int i=len-1; i>=0; i--) printf("%d",outputbuf[i]);
}
	struct AEdge
	{
		int u,v,wl,wr; lllong c;
	} ae[M+3];
	struct Edge
	{
		int u,v,nxt,w; lllong c;
	} e[(M<<2)+3];
	int fe[N+3];
	lllong dis[N+3];
	int que[N+5];
	bool inq[N+3];
	int lst[N+3];
	int n,m,en,s,t; lllong mf,mc;
	void init()
	{
		memset(ae,0,sizeof(ae)); memset(e,0,sizeof(e)); memset(fe,0,sizeof(fe)); memset(dis,0,sizeof(dis)); memset(que,0,sizeof(que)); memset(inq,0,sizeof(inq)); memset(lst,0,sizeof(lst));
		n = m = s = t = 0; mf = mc = (lllong)0;
	}
	void addedge0(int u,int v,int w,lllong c)
	{
//		printf("adde' %d %d %d %lld\n",u,v,w,c);
		en++; e[en].u = u,e[en].v = v,e[en].w = w,e[en].c = c;
		e[en].nxt = fe[u]; fe[u] = en;
		en++; e[en].u = v,e[en].v = u,e[en].w = 0,e[en].c = -c;
		e[en].nxt = fe[v]; fe[v] = en;
	}
	bool spfa()
	{
		for(int i=1; i<=n; i++) dis[i] = -INF2;
		int hd = 1,tl = 2; que[1] = s; dis[1] = 0;
		while(hd!=tl)
		{
			int u = que[hd]; hd++; if(hd>n+1) hd-=n+1;
			for(int i=fe[u]; i; i=e[i].nxt)
			{
				int v = e[i].v;
				if(e[i].w>0&&dis[e[i].v]<dis[u]+e[i].c)
				{
					dis[e[i].v] = dis[u]+e[i].c; lst[e[i].v] = i;
					if(!inq[e[i].v])
					{
						inq[e[i].v] = true;
						que[tl] = e[i].v; tl++; if(tl>n+1) tl-=n+1;
					}
				}
			}
			inq[u] = false;
		}
		return dis[t]!=-INF2;
	}
	void calcflow()
	{
		int flow = 1e5;
		for(int u=t; u!=s; u=e[lst[u]].u)
		{
			flow = min(flow,e[lst[u]].w);
		}
		for(int u=t; u!=s; u=e[lst[u]].u)
		{
			e[lst[u]].w -= flow; e[lst[u]^1].w += flow;
		}
		mf += flow; mc += dis[t]*(lllong)flow;
	}
	void mfmc()
	{
		mf = mc = 0; while(spfa()) {calcflow();}
	}
	void addedge(int u,int v,int wl,int wr,llong c)
	{
//		printf("+ %d %d %d %d %lld\n",u,v,wl,wr,c);
		m++; ae[m].u = u,ae[m].v = v,ae[m].wl = wl,ae[m].wr = wr,ae[m].c = c;
	}
	llong flow(int _n,int _s,int _t,int _mf)
	{
		n = _n,s = _s,t = _t; en = 1; lllong ret = 0ll;
		for(int i=1; i<=m; i++)
		{
			if(ae[i].wl) {addedge0(ae[i].u,ae[i].v,ae[i].wl,INF); ret += (ae[i].c-INF)*(lllong)ae[i].wl;}
			addedge0(ae[i].u,ae[i].v,ae[i].wr-ae[i].wl,ae[i].c);
		}
		mfmc();
//		printf("mf="); write_lll(mf); printf(" mc="); write_lll(mc); printf(" ret="); write_lll(ret); puts("");
		if(mf!=_mf||mc+ret<(lllong)0) {return -1ll;}
		return mc+ret;
	}
}

const int N = 100;
struct Element
{
	int x,y; llong w;
} a[N+3];
struct Condition
{
	int typ,x,y;
} b[N*4+3];
int alx[N+3],aly[N+3],arx[N+3],ary[N+3];
int n,m,mx; llong ans;

int main()
{
	scanf("%d",&n);
	for(int i=1; i<=n; i++)
	{
		scanf("%d%d%lld",&a[i].x,&a[i].y,&a[i].w); mx = max(mx,max(a[i].x,a[i].y));
	}
	scanf("%d",&m);
	for(int i=1; i<=m; i++)
	{
		char str[5]; scanf("%s%d%d",str,&b[i].x,&b[i].y); mx = max(mx,b[i].x);
		b[i].typ = (str[0]=='L'?0:(str[0]=='R'?1:(str[0]=='D'?2:3)));
	}
	mx++;
	for(int k=1; k<=n; k++)
	{
//		printf("\nk=%d\n",k);
		for(int i=0; i<=mx; i++) alx[i] = 0,arx[i] = k,aly[i] = 0,ary[i] = k;
		for(int i=1; i<=m; i++)
		{
			if(b[i].typ==0)
			{
				alx[b[i].x+1] = max(alx[b[i].x+1],k-b[i].y);
			}
			else if(b[i].typ==1)
			{
				arx[b[i].x] = min(arx[b[i].x],b[i].y);
			}
			else if(b[i].typ==2)
			{
				ary[b[i].x] = min(ary[b[i].x],b[i].y);
			}
			else if(b[i].typ==3)
			{
				aly[b[i].x-1] = max(aly[b[i].x-1],k-b[i].y);
			}
		}
		bool ok = true;
		for(int i=0; i<=mx; i++) {if(alx[i]>arx[i]||aly[i]>ary[i]) {ok = false; break;}}
		if(!ok) continue;
//		printf("x: "); for(int i=0; i<=mx; i++) printf("[%d,%d] ",alx[i],arx[i]); puts("");
//		printf("y: "); for(int i=0; i<=mx; i++) printf("[%d,%d] ",aly[i],ary[i]); puts("");
		NetFlow::init();
		for(int i=0; i<=mx; i++)
		{
			NetFlow::addedge(i==0?1:i+2,i+3,alx[i],arx[i],0ll);
		}
		for(int i=0; i<=mx; i++)
		{
			NetFlow::addedge(i+mx+4,i==mx?2:i+mx+5,aly[i],ary[i],0ll);
		}
		for(int i=1; i<=n; i++)
		{
			NetFlow::addedge(a[i].x+3,a[i].y+mx+4,0,1,a[i].w);
		}
		llong cur = NetFlow::flow(mx+mx+4,1,2,k);
		assert(cur>=-1);
//		printf("cur=%lld\n",cur);
		ans = max(ans,cur);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 384