#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#include<assert.h>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
#define SZ(x) ((int)x.size())
using namespace std;
inline LL read()
{
	LL f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int stack[20];
template<typename T>inline void write(T x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
template<typename T>inline void pr1(T x){write(x);putchar(' ');}
template<typename T>inline void pr2(T x){write(x);putchar('\n');}
const int MAXN=85;
const int MAXM=325;
namespace Flow
{
	struct edge{int x,y,c,next;LL d;}a[MAXM*MAXM*4];int len=1,last[MAXN*5];
	void clear(){len=1;memset(last,0,sizeof(last));}
	void ins(int x,int y,int c,LL d)
	{
		len++;a[len].x=x;a[len].y=y;a[len].c=c;a[len].d=d;a[len].next=last[x];last[x]=len;
		len++;a[len].x=y;a[len].y=x;a[len].c=0;a[len].d=-d;a[len].next=last[y];last[y]=len;
	}
	queue<int> li;
	LL d[MAXN*5],S,T;bool vis[MAXN*5];
	int pre[MAXN*5],tmp[MAXN*5];
	bool spfa()
	{
		memset(d,-63,sizeof(d));d[S]=0;li.push(S);vis[S]=1;LL INF=d[0];
		while(!li.empty())
		{
			int x=li.front();li.pop();vis[x]=0;
			for(int k=last[x];k;k=a[k].next)
			{
				int y=a[k].y;
				if(d[y]<d[x]+a[k].d&&a[k].c)
				{
					d[y]=d[x]+a[k].d;pre[y]=x;tmp[y]=k;
					if(!vis[y])vis[y]=1,li.push(y);
				}
			}
		}return d[T]!=INF;
	}
	LL mcf()
	{
		LL ret=0;int minn=99999999;
		while(spfa())
		{
			minn=999999999;
			for(int x=T;x!=S;x=pre[x])minn=min(minn,a[tmp[x]].c);
			ret+=d[T]*minn;
			for(int x=T;x!=S;x=pre[x])a[tmp[x]].c-=minn,a[tmp[x]^1].c+=minn;
		}return ret;
	}
}
using Flow::ins;
using Flow::mcf;
using Flow::S;
using Flow::T;
using Flow::clear;
int n,m;
const int pmx=100;
struct node{int x,y;LL v;}w[MAXN],ask[MAXM],ask1[MAXM];
int lx[MAXM],rx[MAXM],ly[MAXM],ry[MAXM];
LL query(int mx)
{
	clear();
	for(int i=1;i<=m;i++)
	{
		ask1[i]=ask[i];
		if(ask[i].v==1||ask[i].v==3)ask1[i].y=mx-ask1[i].y,ask1[i].y=max(ask1[i].y,0);
		else ask1[i].y=min(ask1[i].y,mx);
	}S=2*pmx+2*n+1;T=S+1;
	for(int i=1;i<=n;i++)ins(w[i].x,w[i].y+pmx,1,w[i].v);
	memset(lx,0,sizeof(lx));memset(rx,63,sizeof(rx));memset(ly,0,sizeof(ly));memset(ry,63,sizeof(ry));
	for(int i=1;i<=m;i++)
	{
		if(ask1[i].v==1)lx[mx-ask1[i].y+1]=max(lx[mx-ask1[i].y+1],ask1[i].x+1);
		else if(ask1[i].v==2)rx[mx-ask1[i].y]=min(rx[mx-ask1[i].y],ask1[i].x-1);
		else if(ask1[i].v==3)ly[mx-ask1[i].y+1]=max(ly[mx-ask1[i].y+1],ask1[i].x+1);
		else ry[mx-ask1[i].y]=min(ry[mx-ask1[i].y],ask1[i].x-1);
	}rx[mx]=min(rx[mx],pmx);ry[mx]=min(ry[mx],pmx);lx[1]=max(lx[1],1);ly[1]=max(ly[1],1);
	for(int i=2;i<=mx;i++)lx[i]=max(lx[i],lx[i-1]),ly[i]=max(ly[i],ly[i-1]);
	for(int i=mx-1;i>=1;i--)rx[i]=min(rx[i],rx[i+1]),ry[i]=min(ry[i],ry[i+1]);
//	for(int i=2;i<=mx;i++)
//	{
//		if(rx[i]!=rx[i-1])lx[i]=max(lx[i],rx[i-1]+1);
//		if(ry[i]!=ry[i-1])ly[i]=max(ly[i],ry[i-1]+1);
//	}
//	for(int i=mx-1;i>=1;i--)
//	{
//		if(lx[i]!=lx[i+1])rx[i]=min(rx[i],lx[i+1]-1);
//		if(ly[i]!=ly[i+1])ry[i]=min(ry[i],ly[i+1]-1);	
//	}
	for(int i=1;i<=mx;i++)
	{
		if(lx[i]>rx[i]||ly[i]>ry[i])return 0;
		for(int j=lx[i];j<=rx[i];j++)ins(2*pmx+i,j,1,0);
		for(int j=ly[i];j<=ry[i];j++)ins(j+pmx,2*pmx+n+i,1,0);
	}
	for(int i=1;i<=mx;i++)ins(S,2*pmx+i,1,0),ins(2*pmx+n+i,T,1,0);
	return mcf();
}
int rd()
{
	char ch=getchar();while(ch<'A'||ch>'Z')ch=getchar();
	return (ch=='L'?1:(ch=='R'?2:(ch=='D'?3:4)));
}
int main()
{
	n=read();
	for(int i=1;i<=n;i++)w[i].x=read(),w[i].y=read(),w[i].v=read();
	m=read();
	for(int i=1;i<=m;i++)ask[i].v=rd(),ask[i].x=read(),ask[i].y=read();
	LL ans=0;
	for(int i=1;i<=n;i++)
		ans=max(ans,query(i));
	pr2(ans);
	return 0;
}


Measured memory_bytes: 896