#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=505,M=200005;
int b[N],a[N],z[N],S,T,flag[N],x[N],y[N],opt[N],lx[N],rx[N],ly[N],ry[N],n,m,sl[M],ne[M],fi[N],zz[M],w[M],tot,dis[N],cur[N];
queue<int> Q;
void jb(int x,int y,int z,int v){
	ne[++tot]=fi[x];fi[x]=tot;zz[tot]=y;sl[tot]=z;w[tot]=v;
	ne[++tot]=fi[y];fi[y]=tot;zz[tot]=x;sl[tot]=0;w[tot]=-v;
}
int get(){
	char s[2];
	scanf("%s",s);
	if (s[0]=='L')return 1;
	if (s[0]=='R')return 2;
	if (s[0]=='D')return 3;
	return 4;
}
int bfs(){
	Q.push(S);
	memset(dis,0x3f3f3f3f,sizeof dis);
	dis[0]=0;
	while (!Q.empty()){
		int now=Q.front();Q.pop();
		flag[now]=0;
		for (int i=fi[now];i;i=ne[i])
			if (sl[i]&&dis[zz[i]]>dis[now]+w[i]){
				dis[zz[i]]=dis[now]+w[i];
				if (!flag[zz[i]]){
					flag[zz[i]]=1;
					Q.push(zz[i]);
				}
			}
	}
	return dis[T]<=1e18;
}
int dfs(int x,int y){
	if (x==T)return y;
	int s=0,b;
	flag[x]=1;
	for (int &i=cur[x];i;i=ne[i])
		if (sl[i]&&!flag[zz[i]]&&dis[zz[i]]==dis[x]+w[i]&&(b=min(sl[i],dfs(zz[i],min(sl[i],y))))){
			s+=b;y-=b;
			sl[i]-=b;
			sl[i^1]+=b;
			if (!y)return s;
		}
	return s;
}
signed main(){
	scanf("%lld",&n);
	for (int i=1;i<=n;i++)scanf("%lld%lld%lld",&x[i],&y[i],&z[i]);
	scanf("%lld",&m);
	for (int i=1;i<=m;i++){
		opt[i]=get();
		scanf("%lld%lld",&a[i],&b[i]);
	}
	S=0;T=1;
	int ans=0;
	for (int k=1;k<=n;k++){
		memset(fi,0,sizeof fi);
		tot=1;
		for (int i=1;i<=k;i++)rx[i]=ry[i]=1e9,lx[i]=ly[i]=0;
		for (int i=1;i<=m;i++){
			if (opt[i]==1&&b[i]<k)lx[b[i]+1]=max(lx[b[i]+1],a[i]+1);
			if (opt[i]==2&&k>b[i])rx[k-b[i]]=min(rx[k-b[i]],a[i]-1);
			if (opt[i]==3&&b[i]<k)ly[b[i]+1]=max(ly[b[i]+1],a[i]+1);
			if (opt[i]==4&&k>b[i])ry[k-b[i]]=min(ry[k-b[i]],a[i]-1);
		}
		for (int i=2;i<=k;i++)lx[i]=max(lx[i-1],lx[i]);
		for (int i=k-1;i;i--)rx[i]=min(rx[i+1],rx[i]);
		for (int i=2;i<=k;i++)ly[i]=max(ly[i-1],ly[i]);
		for (int i=k-1;i;i--)ry[i]=min(ry[i+1],ry[i]);
		for (int i=2;i<=k+1;i++)jb(S,i,1,0);
		for (int i=2;i<=k+1;i++)jb(i+k,T,1,0);
		for (int i=1;i<=k;i++)
			for (int j=1;j<=n;j++)
				if (lx[i]<=x[j]&&rx[i]>=x[j])jb(i+1,j+2*k+1,1,0);
		for (int i=1;i<=k;i++)
			for (int j=1;j<=n;j++)
				if (ly[i]<=y[j]&&ry[i]>=y[j])jb(j+2*k+1+n,i+k+1,1,0);
		for (int i=1;i<=n;i++)jb(i+2*k+1,i+n+2*k+1,1,-z[i]);
		int ansc=0,ansm=0;
		while (bfs()){
			for (int i=0;i<=2*k+1+2*n;i++)cur[i]=fi[i];
			int t=dfs(S,1e9);
			ansm+=t;
			ansc+=t*dis[T];
			for (int i=0;i<=2*k+1+2*n;i++)flag[i]=0;
		}
		if (ansm==k)ans=max(ans,-ansc);
	}
	printf("%lld\n",ans);
}
