#include <bits/stdc++.h>
#define clr(x) memset(x,0,sizeof x)
#define For(i,a,b) for (int i=(a);i<=(b);i++)
#define Fod(i,b,a) for (int i=(b);i>=(a);i--)
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
#define y0 _y0
#define y1 _y1
#define outval(x) cerr<<#x" = "<<x<<endl
#define outtag(x) cerr<<"-----------------"#x"-----------------\n"
#define outarr(a,L,R) cerr<<#a"["<<L<<".."<<R<<"] = ";\
                    For(_x,L,R) cerr<<a[_x]<<" ";cerr<<endl;
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair <int,int> pii;
LL read(){
    LL x=0,f=0;
    char ch=getchar();
    while (!isdigit(ch))
        f=ch=='-',ch=getchar();
    while (isdigit(ch))
        x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
    return f?-x:x;
}
const int N=85,M=325;
const LL LLINF=1e18;
int n,m;
struct Node{
	int x,y;
	LL v;
}a[N];
struct Limit{
	char c;
	int a,b;
}l[M];
namespace flows{
	const int N=85*4,M=85*85*2*2;
	struct Edge{
		int x,y,nxt,cap;
		LL cost;
		Edge(){}
		Edge(int _x,int _y,int _nxt,int _cap,LL _cost){
			x=_x,y=_y,nxt=_nxt,cap=_cap,cost=_cost;
		}
	}e[M];
	int n,S,T,cnt;
	int fst[N],cur[N],vis[N];
	LL dis[N];
	void clear(int _n,int _S,int _T){
		n=_n,S=_S,T=_T;
		clr(fst),cnt=1;
	}
	void Add(int x,int y,int cap,LL cost){
		e[++cnt]=Edge(x,y,fst[x],cap,cost),fst[x]=cnt;
		e[++cnt]=Edge(y,x,fst[y],0,-cost),fst[y]=cnt;
	}
	int bfs(){
		static queue <int> q;
		while (!q.empty())
			q.pop();
		For(i,1,n)
			dis[i]=-LLINF,vis[i]=0;
		dis[S]=0,q.push(S);
		while (!q.empty()){
			int x=q.front();
			q.pop();
			vis[x]=0;
			for (int i=fst[x];i;i=e[i].nxt){
				int y=e[i].y;
				if (e[i].cap&&dis[x]+e[i].cost>dis[y]){
					dis[y]=dis[x]+e[i].cost;
					if (!vis[y]){
						vis[y]=1;
						q.push(y);
					}
				}
			}
		}
		return dis[T]>-LLINF;
	}
	int dfs(int x,int Lim){
		if (x==T||!Lim)
			return Lim;
		int rem=Lim;
		vis[x]=1;
		for (int &i=cur[x];i;i=e[i].nxt){
			int y=e[i].y;
			if (!vis[y]&&e[i].cap&&dis[x]+e[i].cost==dis[y]){
				int d=dfs(y,min(rem,e[i].cap));
				rem-=d,e[i].cap-=d,e[i^1].cap+=d;
			}
		}
		vis[x]=0;
		return Lim-rem;
	}
	LL Dinic(){
		LL cost=0;
		while (bfs()){
			clr(vis);
			For(i,1,n)
				cur[i]=fst[i];
			int d=dfs(S,1e9);
			cost+=dis[T]*d;
		}
		return cost;
	}
}
void ckmax(int &x,int y){
	if (x<y)
		x=y;
}
void ckmin(int &x,int y){
	if (x>y)
		x=y;
}
int x0[N],x1[N],y0[N],y1[N];
int main(){
	n=read();
	For(i,1,n)
		a[i].x=read(),a[i].y=read(),a[i].v=read();
	m=read();
	For(i,1,m){
		char s[10];
		cin>>s>>l[i].a>>l[i].b;
		l[i].c=s[0];
	}
	LL ans=0;
	For(k,1,n){
		int S=(n+k)*2+1,T=S+1;
		flows::clear(T,S,T);
		For(i,0,k+1){
			x0[i]=y0[i]=0;
			x1[i]=y1[i]=101;
		}
		For(i,1,m){
			if (l[i].b>=k)
				continue;
			if (l[i].c=='L')
				ckmax(x0[l[i].b+1],l[i].a);
			if (l[i].c=='R')
				ckmin(x1[k-l[i].b],l[i].a);
			if (l[i].c=='D')
				ckmax(y0[l[i].b+1],l[i].a);
			if (l[i].c=='U')
				ckmin(y1[k-l[i].b],l[i].a);
		}
		For(i,1,k){
			ckmax(x0[i],x0[i-1]);
			ckmax(y0[i],y0[i-1]);
		}
		Fod(i,k,1){
			ckmin(x1[i],x1[i+1]);
			ckmin(y1[i],y1[i+1]);
		}
		For(i,1,n)
			flows::Add(i,i+n,1,a[i].v);
		For(i,1,k){
			flows::Add(S,i+n*2,1,0);
			flows::Add(i+n*2+k,T,1,0);
			For(j,1,n){
				if (x0[i]<a[j].x&&a[j].x<x1[i])
					flows::Add(i+n*2,j,1,0);
				if (y0[i]<a[j].y&&a[j].y<y1[i])
					flows::Add(j+n,i+n*2+k,1,0);
			}
		}
		ans=max(ans,flows::Dinic());
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 768