#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;
typedef pair<ll,int> pli;

template<class T> inline void read(T &x){
	int f=0;x=0;char ch=getchar();
	for(;!isdigit(ch);ch=getchar())f|=(ch=='-');
	for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';
	if(f)x=-x;
}

const int N=1005,iinf=1e9;
const ll inf=1e18+9,mx=1e15+26;
namespace G{
	struct edge{int v,f,c,id;ll w;};vector<edge> e[N];
	int r[N],ins[N],n,s,t; ll d[N],f[N];
	void add(int u,int v,int c,ll w){
		e[u].pb((edge){v,0,c,(int)e[v].size(),w});
		e[v].pb((edge){u,0,0,(int)e[u].size()-1,-w});
	}
	priority_queue<pli,vector<pli>,greater<pli> >Q;
	int dij(){
		rep(i,1,n){
			f[i]=min(f[i]+d[i],inf);
			d[i]=(i==s?0:inf);
		}
		for(Q.push(mp(0,s));!Q.empty();){
			pii t=Q.top(); Q.pop();
			if(t.fi>d[t.se]) continue;
			for(int u=t.se,k=0;k<(int)e[u].size();k++){
				edge &v=e[u][k];
				if(v.f<v.c&&f[u]+d[u]+v.w<f[v.v]+d[v.v]){
					d[v.v]=f[u]+d[u]+v.w-f[v.v];
					Q.push(mp(d[v.v],v.v));
				}
			}
		}
		return d[t]<inf;
	}
	int dfs(int u,int a){
		if(u==t) return a;
		int res=0; ins[u]=1;
		for(int &k=r[u];k<(int)e[u].size();k++){
			edge &v=e[u][k];
			if(v.f<v.c&&f[u]+d[u]+v.w==f[v.v]+d[v.v]&&!ins[v.v]){
				int ret=dfs(v.v,min(a,v.c-v.f));
				v.f+=ret,e[v.v][v.id].f-=ret,res+=ret;
				if(!(a-=ret)) break;
			}
		}
		return ins[u]=0,res;
	}
	void flow(int &flow,ll &cost){
		fill(d+1,d+n+1,0),fill(f+1,f+n+1,0);
		while(dij()){
			fill(r+1,r+n+1,0);
			int ret=dfs(s,iinf);
			flow+=ret,cost+=(d[t]+f[t])*ret;
		}
	}
}

const int lim=100;
int xl[N],xr[N],yl[N],yr[N],d[N];
int L[N],R[N],U[N],D[N];
int x[N],y[N],X[N],Y[N];
ll v[N],ans;
int n,m,a,b;

void add(int u,int v,int l,int r){
	G::add(u,v,r-l,0),d[u]+=l,d[v]-=l;
}

void solve(int c){
	int s=1,t=lim+2,S=lim+lim+3,T=S+1;
	rep(i,1,lim){
		xl[i]=max(0,c-L[i-1]),xr[i]=R[i];
		yl[i]=max(0,c-D[i-1]),yr[i]=U[i];
		if(xl[i]>xr[i]||yl[i]>yr[i]) return;
	}
	fill(d+1,d+T+1,0);
	G::n=T,G::s=S,G::t=T;
	rep(i,1,T) G::e[i].clear();
	rep(i,1,lim){
		add(s+i-1,s+i,xl[i],xr[i]);
		add(t+i,t+i-1,yl[i],yr[i]);
	}
	rep(i,1,n){
		G::add(s+x[i],t+y[i],1,mx-v[i]);
	}
	add(t,s,c,c);
	int aim=0,flow=0; ll cost=0;
	rep(i,1,S-1){
		if(d[i]>0) G::add(i,T,d[i],0),aim+=d[i];
		if(d[i]<0) G::add(S,i,-d[i],0);
	}
	G::flow(flow,cost);
	if(aim==flow) ans=max(ans,mx*c-cost);
}

int main(){
	read(n);
	rep(i,1,n){
		read(x[i]),read(y[i]),read(v[i]);
		X[x[i]]++,Y[y[i]]++;
	}
	rep(i,1,lim){
		X[i]+=X[i-1],Y[i]+=Y[i-1];
		L[i]=X[i],R[i]=n-X[i-1];
		D[i]=Y[i],U[i]=n-Y[i-1];
	}
	read(m);
	rep(i,1,m){
		static char op[5];
		scanf("%s",op);
		read(a),read(b);
		if(op[0]=='L') L[a]=min(L[a],b);
		if(op[0]=='R') R[a]=min(R[a],b);
		if(op[0]=='U') U[a]=min(U[a],b);
		if(op[0]=='D') D[a]=min(D[a],b);
	}
	per(i,lim-1,1){
		L[i]=min(L[i],L[i+1]);
		D[i]=min(D[i],D[i+1]);
	}
	rep(i,2,lim){
		R[i]=min(R[i],R[i-1]);
		U[i]=min(U[i],U[i-1]);
	}
	per(i,n,1) if(i*mx>ans) solve(i);
	cout<<ans<<endl;
	return 0;
}