// This amazing code is by Eric Sunli Chen.
#include<bits/stdc++.h>
using namespace std;
template<typename T> bool get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'&&t!=EOF; t=getchar());
	if(t=='-')neg=true,t=getchar();if(t==EOF)return false;
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;return true;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) (get1(a)&&get1(b))
#define get3(a,b,c) (get1(a)&&get2(b,c))
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
typedef vector<int> vi;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

const int maxn=233;
const int maxm=100111;
struct mincost_flow
{
	struct edge{int to,cap;LL cost;};
	int head[maxn],nxt[maxm<<1],iter[maxn],tot=1;
	edge e[maxm<<1];
	void addedge(int u,int v,int cap,LL cost)
	{
//		printf("Edge %d %d %d %lld\n",u,v,cap,cost);
		nxt[++tot]=head[u];
		head[u]=tot;
		e[tot]=edge{v,cap,cost};
		nxt[++tot]=head[v];
		head[v]=tot;
		e[tot]=edge{u,0,-cost};
	}
	void clear()
	{
		memset(head,0,sizeof(head));
		tot=1;
	}
	bool inq[maxn];int q[maxn],pre[maxn];
	LL dist[maxn];
	void spfa(int s)
	{
		memset(dist,0x3f,sizeof(dist));
		dist[s]=0;int fr=0,rr=0;q[rr++]=s;
		while(fr!=rr)
		{
			int x=q[fr++];if(fr==maxn)fr=0;
			inq[x]=0;
			for(int i=head[x];i;i=nxt[i])if(e[i].cap&&dist[e[i].to]>dist[x]+e[i].cost)
			{
				dist[e[i].to]=dist[x]+e[i].cost;
				pre[e[i].to]=i;
				if(!inq[e[i].to])
				{
					inq[e[i].to]=1;
					if(fr==rr||dist[q[fr]]<=dist[e[i].to])
					{
						q[rr++]=e[i].to;
						if(rr==maxn)rr=0;
					}
					else
					{
						if(fr==0)fr=maxn;
						q[--fr]=e[i].to;
					}
				}
			}
		}
	}
	LL augment(int t,int s,int&f)
	{
		int d=f,cur;
		for(cur=t;cur!=s;cur=e[pre[cur]^1].to)d=min(d,e[pre[cur]].cap);
		f-=d;
		for(cur=t;cur!=s;cur=e[pre[cur]^1].to)
		{
			e[pre[cur]].cap-=d;
			e[pre[cur]^1].cap+=d;
		}
		return dist[t]*d;
	}
	LL mincostflow(int s,int t,int f)
	{
		LL ret=0;
		while(f)
		{
			spfa(s);
			if(dist[t]==0x3f3f3f3f3f3f3f3fll)return 0;
			ret+=augment(t,s,f);
		}
		return ret;
	}
}thor;

int n,m,x[111],y[111];LL v[111];
int tp[411],a[411],b[411];

int l[111],r[111],ll[111],rr[111];
LL calc(int sz)
{
	thor.clear();int NUM=101,s=NUM+NUM+1,t=s+1,S=t+1,T=S+1;
	for(int i=1;i<=n;i++)thor.addedge(x[i],y[i]+NUM,1,-v[i]);
	for(int i=0;i<NUM;i++)
	{
		l[i]=ll[i]=0;
		r[i]=rr[i]=sz;
	}
	for(int i=1;i<=m;i++)
	{
		if(tp[i]==0)r[a[i]]=min(r[a[i]],b[i]);
		else if(tp[i]==1)l[a[i]-1]=max(l[a[i]-1],sz-b[i]);
		else if(tp[i]==2)rr[a[i]]=min(rr[a[i]],b[i]);
		else if(tp[i]==3)ll[a[i]-1]=max(ll[a[i]-1],sz-b[i]);
	}
	for(int i=0;i<NUM;i++)if(l[i]>r[i]||ll[i]>rr[i])return 0;
	if(l[0]||ll[0])return 0;
	
	int sum=sz;
	thor.addedge(s,NUM,sz,0);
	thor.addedge(NUM+NUM,t,sz,0);
	thor.addedge(S,s,sz,0);
	thor.addedge(t,T,sz,0);
	for(int i=NUM-1;i>=1;i--)
	{
		if(l[i]<r[i])thor.addedge(i+1,i,r[i]-l[i],0);
		if(l[i])
		{
			thor.addedge(S,i,l[i],0);
			thor.addedge(i+1,T,l[i],0);
			sum+=l[i];
		}
	}
	for(int i=NUM-1;i>=1;i--)
	{
		if(ll[i]<rr[i])thor.addedge(i+NUM,i+NUM+1,rr[i]-ll[i],0);
		if(ll[i])
		{
			thor.addedge(S,i+NUM+1,ll[i],0);
			thor.addedge(i+NUM,T,ll[i],0);
			sum+=ll[i];
		}
	}
	LL ret=thor.mincostflow(S,T,sum);
	return -ret;
}

int main()
{
	get1(n);
	for(int i=1;i<=n;i++)get3(x[i],y[i],v[i]);
	get1(m);
	char op[4];
	for(int i=1;i<=m;i++)
	{
		scanf("%s",op);get2(a[i],b[i]);
		if(op[0]=='L')tp[i]=0;
		else if(op[0]=='R')tp[i]=1;
		else if(op[0]=='D')tp[i]=2;
		else tp[i]=3;
	}
	LL ans=0;
	for(int i=1;i<=n;i++)ans=max(ans,calc(i));
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 384