//Zory-2019
#include<cmath>
#include<ctime>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<map>
#include<set>
#include<queue>
#include<deque>
#include<stack>
#include<bitset>
#include<vector>
#include<algorithm>
#include<iostream>
#include<deque>
using namespace std;
namespace mine
{
	typedef long long ll;
	#define double long double
	const int INF=0x3f3f3f3f;
	const ll LLINF=0x3f3f3f3f3f3f3f3fll;
	ll qread()
	{
		ll ans=0;char c=getchar();int f=1;
		while(c<'0' or c>'9') {if(c=='-') f=-1;c=getchar();}
		while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
		return ans*f;
	}
	void write(ll num)
	{
		if(num<0) {num=-num;putchar('-');}
		if(num>9) write(num/10);
		putchar('0'+num%10);
	}
	void writeln(int num){write(num);puts("");}
	#define FR first
	#define SE second
	#define MP make_pair
	#define pr pair<int,int>
	#define PB push_back
	inline void chmax(int &x,int y) {x=x>y?x:y;}
	inline void chmin(int &x,int y) {x=x<y?x:y;}

	const int MAX_N=1100,MAX_M=1e5;
	int hou[MAX_N];
	struct Edge{int y,g,c;ll w;}e[MAX_M*2];
	int ln=0;int oth(int x){return x&1?x+1:x-1;}
	void ins(int x,int y,int c,ll w)
	{
		if(c==0) return;
		e[++ln]=(Edge){y,hou[x],c,w};hou[x]=ln;
		e[++ln]=(Edge){x,hou[y],0,-w};hou[y]=ln;
	}
	int st,ed;queue<int> qq;bool v[MAX_N];
	ll dis[MAX_N];int fm[MAX_N],mic[MAX_N];
	ll ans;int flow;
	bool solve()
	{
		memset(dis,-0x3f,sizeof dis);
		memset(v,0,sizeof v);v[st]=1;
		qq.push(st);mic[st]=INF;dis[st]=0;
		while(qq.size())
		{
			int x=qq.front();qq.pop();
			for(int k=hou[x];k>0;k=e[k].g)
			{
				int y=e[k].y;
				if(dis[y]<dis[x]+e[k].w and e[k].c)
				{
					dis[y]=dis[x]+e[k].w;
					mic[y]=min(mic[x],e[k].c);fm[y]=k;
					if(!v[y]) v[y]=1,qq.push(y);
				}
			}
			v[x]=0;
		}
		if(mic[ed]==0 or dis[ed]<0) return 0;
		ans+=dis[ed]*mic[ed];flow+=mic[ed];
		for(int x=ed;x!=st;x=e[oth(fm[x])].y) e[fm[x]].c-=mic[ed],e[oth(fm[x])].c+=mic[ed];
		return 1;
	}

	int n,m;ll val[MAX_N];
	pr pt[MAX_N];struct Qes{int a,b;char op[10];}q[MAX_N];
	int fl[2][MAX_N],fr[2][MAX_N];
	ll getans(int T)
	{
		ln=0;memset(hou,0,sizeof hou);st=0,ed=n*4+1;
		for(int i=1;i<=n;i++) ins(i,n+i,1,val[i]);
		memset(fl,0,sizeof fl);memset(fr,0x3f,sizeof fr);fl[0][1]=1;fr[0][T]=100;fl[1][1]=1;fr[1][T]=100;
		for(int i=1;i<=m;i++) if(q[i].b<T)
		{
			if(q[i].op[0]=='L') chmax(fl[0][q[i].b+1],q[i].a+1);
			if(q[i].op[0]=='R') chmin(fr[0][T-q[i].b],q[i].a-1);
			if(q[i].op[0]=='D') chmax(fl[1][q[i].b+1],q[i].a+1);
			if(q[i].op[0]=='U') chmin(fr[1][T-q[i].b],q[i].a-1);
		}
		for(int i=1;i<T;i++) chmax(fl[0][i+1],fl[0][i]);for(int i=T;i>=2;i--) chmin(fr[0][i-1],fr[0][i]);
		for(int i=1;i<=T;i++)
		{
			ins(st,n*2+i,1,0);
			for(int j=1;j<=n;j++) if(fl[0][i]<=pt[j].FR and pt[j].FR<=fr[0][i]) ins(n*2+i,j,1,0)/*,printf("%d ",j)*/;
			// puts("");
		}
		for(int i=1;i<T;i++) chmax(fl[1][i+1],fl[1][i]);for(int i=T;i>=2;i--) chmin(fr[1][i-1],fr[1][i]);
		for(int i=1;i<=T;i++)
		{
			ins(n*3+i,ed,1,0);
			for(int j=1;j<=n;j++) if(fl[1][i]<=pt[j].SE and pt[j].SE<=fr[1][i]) ins(n+j,n*3+i,1,0)/*,printf("%d ",j)*/;
			// puts("");
		}
		ans=0;flow=0;while(solve()) ;
		// printf("T=%d flow=%d ans=%lld\n",T,flow,ans);
		return ans*(flow==T);
	}
	void main()
	{
		n=qread();for(int i=1;i<=n;i++) scanf("%d%d%lld",&pt[i].FR,&pt[i].SE,&val[i]);
		m=qread();for(int i=1;i<=m;i++) scanf("%s%d%d",q[i].op,&q[i].a,&q[i].b);
		ll ans=0;for(int T=1;T<=n;T++) ans=max(ans,getans(T));
		printf("%lld",ans);
	}
};
int main()
{
	srand(time(0));
	mine::main();
}


Measured memory_bytes: 768