#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<queue>
#include<algorithm>

using namespace std;
#define LL long long
#define fgx cerr<<"--------------"<<endl;
#define dgx cerr<<"=============="<<endl;

inline LL read(){
	LL x=0,f=1; char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
	for(;isdigit(c);c=getchar()) x=x*10+c-'0';
	return x*f;
}
const LL MAXN = 500010;
const LL INF = 1e17;

LL N; LL d[2][MAXN+1],V[MAXN+1];
LL Cost[MAXN+1]; LL Node[MAXN+1],Next[MAXN+1],C[MAXN+1],Root[MAXN+1];
LL cnt; LL S,T;
inline void addedge(LL u,LL v,LL c,LL w){ Cost[cnt]=w; C[cnt]=c; Node[cnt]=v; Next[cnt]=Root[u]; Root[u]=cnt++; }
inline void insert(LL u,LL v,LL c,LL w){ w=-w; addedge(u,v,c,w); addedge(v,u,0,-w); return ; }
LL dis[MAXN+1]; bool inq[MAXN+1];
LL ans,ret;
inline bool BFS(){
	deque<LL> que; for(LL i=0;i<=T;i++) dis[i]=INF,inq[i]=0;
	dis[T]=0; que.push_back(T); inq[T]=true;
	int td=0;
	while(!que.empty()){
	    LL k=que.front(); que.pop_front(); ++td;
		for(LL x=Root[k];x!=-1;x=Next[x]){
		    LL v=Node[x];
		    if(C[x^1]>0&&dis[v]>dis[k]-Cost[x]){
		        dis[v]=dis[k]-Cost[x];
				if(!inq[v]){
					inq[v]=true;
				    if(que.empty()||dis[v]<=dis[que.front()]) que.push_front(v);
				    else que.push_back(v);
			    }
		    }
	    }inq[k]=false;
	}  return dis[S]<INF;
} LL fans;
inline LL DFS(LL k,LL t){
    if(k==T) {inq[k]=1;return t;} 
	inq[k]=1; LL res=0;
	for(LL x=Root[k];x!=-1;x=Next[x]){
	    LL v=Node[x];
	    if(C[x]>0&&!inq[v]&&dis[v]==dis[k]-Cost[x]){
	        LL tmp=DFS(v,min(t,C[x]));
			if(!tmp) continue; C[x]-=tmp; C[x^1]+=tmp;
			res+=tmp; t-=tmp; fans+=(LL)tmp*Cost[x]; if(!t) return res;	
	    }
    } return res;
}
#define fr first
#define sc second
inline void Max(LL &a,LL b){ a=max(a,b); }
inline void Min(LL &a,LL b){ a=min(a,b); }
LL L[2][MAXN+1],R[2][MAXN+1];
LL M; char ch[5];
vector<pair<LL,LL> > vec[4];
int sta[MAXN+1],sta2[MAXN+1],sta3[MAXN+1];
inline void check(LL K){
	for(LL i=0;i<=K+1;i++) L[0][i]=L[1][i]=1,R[0][i]=R[1][i]=100; cnt=0;
	for(LL i=0;i<=N*2+2*K+1;i++) Root[i]=-1;
	for(LL i=0,l=vec[0].size();i<l;i++) Max(L[0][vec[0][i].fr+1],vec[0][i].sc+1);
	for(LL i=0,l=vec[1].size();i<l;i++) if(vec[1][i].fr<K) Min(R[0][K-vec[1][i].fr],vec[1][i].sc-1);
	for(LL i=0,l=vec[2].size();i<l;i++) Max(L[1][vec[2][i].fr+1],vec[2][i].sc+1);
	for(LL i=0,l=vec[3].size();i<l;i++) if(vec[3][i].fr<K) Min(R[1][K-vec[3][i].fr],vec[3][i].sc-1);
	S=0,T=N*2+K*2+1; int top=0,top2=0,top3=0;
	for(LL i=1;i<=N;i++) insert(i,N+i,1,V[i]),sta[++top]=cnt-2;
	for(LL i=0;i<2;i++){
		for(LL j=1;j<=K;j++) L[i][j]=max(L[i][j],L[i][j-1]);
		for(LL j=K-1;j>=0;j--) R[i][j]=min(R[i][j],R[i][j+1]);
		for(LL j=1;j<=K;j++){
			if(!i) insert(S,N*2+j,1,0),sta2[++top2]=cnt-2;
			else insert(N*2+K+j,T,1,0),sta3[++top3]=cnt-2;
			
					//if(K==5&&!i) cout<<"gg:"<<L[i][j]<<" "<<R[i][j]<<endl;
			for(LL k=1;k<=N;k++){
				if(d[i][k]>=L[i][j]&&d[i][k]<=R[i][j]){
					if(!i) insert(N*2+j,k,1,0);
					else insert(N+k,N*2+K+j,1,0);
				}
			}
		}
	} fans=0;
	ret=0; while(BFS()) ret+=DFS(S,INF);
	ans=max(ans,-fans); //cout<<-fans<<" "<<ret<<" "<<K<<endl;
	//for(int i=1;i<=top;i++) cout<<C[sta[i]]<<" "; cout<<endl; for(int i=1;i<=top2;i++) cout<<C[sta2[i]]<<" "; cout<<endl;for(int i=1;i<=top3;i++) cout<<C[sta3[i]]<<" "; cout<<endl; 
	 return ; 
}

int main(){
	//freopen("a.in","r",stdin);
	//freopen("a2.out","w",stdout);
	N=read();
	memset(Root,-1,sizeof(Root));
	for(LL i=1;i<=N;i++){
		d[0][i]=read(),d[1][i]=read(),V[i]=read();
	} M=read();
	for(LL i=1;i<=M;i++){
		scanf("%s",ch+1); LL a=read(),b=read();
		LL opr; if(ch[1]=='L') opr=0;
		else if(ch[1]=='R') opr=1;
		else if(ch[1]=='U') opr=3;
		else opr=2; vec[opr].push_back(make_pair(b,a));
	}
	for(LL i=0;i<4;i++) sort(vec[i].begin(),vec[i].end());
	for(LL K=1;K<=N;K++) check(K);
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 31104