#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<ctime>
#include<set>
#include<map>
#include<queue>
#include<stack>
#define sqr(x) ((x)*(x))
#define fz1(i,n) for ((i)=1;(i)<=(n);(i)++)
#define fd1(i,n) for ((i)=(n);(i)>=1;(i)--)
#define fz0g(i,n) for ((i)=0;(i)<=(n);(i)++)
#define fd0g(i,n) for ((i)=(n);(i)>=0;(i)--)
#define fz0k(i,n) for ((i)=0;(i)<(n);(i)++)
#define fd0k(i,n) for ((i)=(long long)((n)-1);(i)>=0;(i)--)
#define fz(i,x,y) for ((i)=(x);(i)<=(y);(i)++)
#define fd(i,y,x) for ((i)=(y);(i)>=(x);(i)--)
#define fzin fz1(i,n)
#define fzim fz1(i,m)
#define fzjn fz1(j,n)
#define fzjm fz1(j,m)
#define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define rdst(st,len){static char ss[len];scanf(" %s",ss);(st)=ss;}
//#define T_ long long
using namespace std;
//struct bit{T_ arr[1000005];long long lowbit(long long x){return x&(-x);}void add(long long x,T_ y){for (long long i=x;i<=n;i+=lowbit(i)) arr[i]+=y;}T_ query(long long x){T_ s=0;for (long long i=x;i>0;i-=lowbit(i)) s+=arr[i];return s;}};
//struct seg{struct treedot{long long l,r;T_ sum,add;void update(T_ x){sum+=(r-l+1)*x; add+=x;}}c[800005];void pushdown(long long id){if (c[id].add){c[id*2].update(c[id].add);c[id*2+1].update(c[id].add);c[id].add=0;}}void pushup(long long id){c[id].sum=c[id*2].sum+c[id*2+1].sum;}void build(long long id,long long l,long long r){if (l>r) return;c[id].l=l;c[id].r=r;c[id].sum=0;c[id].add=0;if (l==r) c[id].sum=0;else{long long mid=l+(r-l)/2;build(id*2,l,mid);build(id*2+1,mid+1,r);pushup(id);}}void update(long long id,long long le,long long ri,T_ x){if (le>c[id].r||ri<c[id].l) return;if (le<=c[id].l&&c[id].r<=ri) c[id].update(x);else{pushdown(id);update(id*2,le,ri,x);update(id*2+1,le,ri,x);pushup(id);}}T_ query(long long id,long long le,long long ri){if (ri<c[id].l||c[id].r<le) return 0;if (le<=c[id].l&&c[id].r<=ri) return c[id].sum;T_ ans=0;pushdown(id);ans+=query(id*2,le,ri);ans+=query(id*2+1,le,ri);pushup(id);return ans;}};
//struct bit_2d{T_ a[2005][2005];long long lowbit(long long x){return x&(-x);}void add(long long x,long long y,T_ z){long long i,j;for (i=x;i<=2000;i+=lowbit(i)){for (j=y;j<=2000;j+=lowbit(j)){a[i][j]+=z;}}}T_ query(long long x,long long y){long long i,j;T_ s=0;for (i=x;i;i-=lowbit(i)){for (j=y;j;j-=lowbit(j)){s+=a[i][j];}}return s;}T_ query(long long x,long long y,long long xx,long long yy){return query(xx,yy)-query(x-1,yy)-query(xx,y-1)+query(x-1,y-1);}};
long long n,m,i,j,k,dis[325],cnt,a[325],b[325],v[325],s=0,t=321,l[325],r[325],u[325],d[325],x,y,cst,inq[325],vis[325],ans;
vector<long long> allx,ally;
char c[325],ca[325],cb[325];
struct ii
{
	long long y,z,d;
}e[1000005];
vector<long long> bi[10005];
void init()
{
	int i;fz0g(i,321) bi[i].clear();cnt=0;
}
void add(long long x,long long y,long long z,long long d)
{
	cnt++;bi[x].push_back(cnt*2-2);bi[y].push_back(cnt*2-1);
	e[cnt*2-2]=(ii){y,z,d};e[cnt*2-1]=(ii){x,0,-d};
}
bool bfs(long long s,long long t)
{
	memset(dis,-0x18,sizeof(dis));dis[s]=0;queue<long long> qx;qx.push(s);inq[s]=1;
	while (!qx.empty()){
		long long x=qx.front();qx.pop();inq[x]=0;ff(bi[x],it) if (e[*it].z){
			long long y=e[*it].y,z=dis[x]+e[*it].d;
			if (dis[y]<z){
				dis[y]=z;
				if (!inq[y]){
					inq[y]=1;qx.push(y);
				}
			}
		}
	}return dis[t]>dis[324];
}
long long dfs(long long x,long long tt,long long flw)
{
	if (x==tt) vis[tt]=1;
	if (x==tt||!flw) return flw;if (vis[x])return 0;vis[x]=1;long long ans=0;ff(bi[x],it) if (e[*it].z&&dis[e[*it].y]==dis[x]+e[*it].d){
		long long t=dfs(e[*it].y,tt,min(flw,e[*it].z));cst+=t*e[*it].d;ans+=t;flw-=t;e[*it].z-=t;e[(*it)^1].z+=t;if (!flw) break;
	}return ans;
}
bool dinic(long long s,long long t,long long aa)
{
	long long ans=0;while (bfs(s,t)){
		do{
			memset(vis,0,sizeof(vis));
			ans+=dfs(s,t,aa);
		}while (vis[t]);
	}if (ans==aa) return 1;return 0;
}
int main()
{
	scanf("%lld",&n);
	fz1(i,n){
		scanf("%lld%lld%lld",&a[i],&b[i],&v[i]);
//		allx.push_back(a[i]);ally.push_back(b[i]);
	}//sort(allx.begin(),allx.end());allx.resize(unique(allx.begin(),allx.end())-allx.begin());sort(ally.begin(),ally.end());ally.resize(unique(ally.begin(),ally.end())-ally.begin());
	/*fz1(i,n){
		a[i]=upper_bound(allx.begin(),allx.end(),a[i])-allx.begin();
		b[i]=upper_bound(ally.begin(),ally.end(),b[i])-ally.begin();
	}*/
	scanf("%lld",&m);fz1(i,m){
		scanf(" %c%lld%lld",&c[i],&ca[i],&cb[i]);
	}
	ans=0;
	fz1(i,n){
		cst=0;init();
		fz1(j,i){
			l[i]=d[i]=0;
			r[i]=u[i]=0x1818181818181818ll;
		}
		fz1(j,m) if (cb[j]<i){
			if (c[j]=='L') l[cb[j]+1]=max(l[cb[j]+1],ca[j]+1ll);
			if (c[j]=='R') r[i-cb[j]]=min(r[i-cb[j]],ca[j]-1ll);
			if (c[j]=='D') d[cb[j]+1]=max(d[cb[j]+1],ca[j]+1ll);
			if (c[j]=='U') u[i-cb[j]]=min(u[i-cb[j]],ca[j]-1ll);
		}
		fz(j,2,i){
			l[j]=max(l[j],l[j-1]);
			d[j]=max(d[j],d[j-1]);
		}
		fd(j,i-1,1){
			r[j]=min(r[j],r[j+1]);
			u[j]=min(u[j],u[j+1]);
		}
		fz1(j,i)fz1(k,n){
			if (l[j]<=a[k]&&a[k]<=r[j]){
				add(j,n+k,1,0);
			}
			if (d[j]<=b[k]&&b[k]<=u[j]){
				add(n+n+k,n+n+n+j,1,0);
			}
		}
		fz1(j,i){
			add(s,j,1,0);add(n+n+n+j,t,1,0);
		}fz1(j,n){
			add(j+n,j+n+n,1,v[j]);
		}if (dinic(s,t,i)) ans=max(ans,cst);
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 1152