#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
template<class T> inline void umin(T &x, T y){x=x<y?x:y;}
template<class T> inline void umax(T &x, T y){x=x>y?x:y;}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 2666;
int n,A[N],B[N];ll C[N],res;
int D[N],E[N],F[N];
//namespace flow{//¶àÂ·Ôö¹ã 
	const int M = 200000, inf = 0x3f3f3f3f;const ll biginf=1e17;
	int S,T,edgenum=1,head[N],cur[N],to[M],nxt[M],cap[M];ll val[M];
	inline void addedge(int u, int v, int c, ll w){
		to[++edgenum]=v;cap[edgenum]=c;val[edgenum]=w;
		nxt[edgenum]=head[u];head[u]=edgenum;
	}
	inline void add(int u, int v, int c, ll w){
		assert(u<=T&&v<=T&&u&&v);w=-w;
		addedge(u,v,c,w);addedge(v,u,0,-w);
	}
	int rec[N],q[N];bool vis[N];ll dis[N];
	inline void inc(int &x){x++;x=x==N?0:x;}
	inline bool spfa(){
		int f=0,r=1;rep(i,0,T)dis[i]=biginf;dis[T]=0;q[f]=T;
		while(f!=r){
			int u=q[f];inc(f);vis[u]=0;
			L(i,u)if(cap[i^1]&&dis[to[i]]>dis[u]+val[i^1]){
				dis[to[i]]=dis[u]+val[i^1];rec[to[i]]=i;
				if(!vis[to[i]]){
					q[r]=to[i],inc(r);vis[to[i]]=1;//SLF»á±äÂý£¡£¡ 
				}
			}
		}
		return dis[S]<biginf;
	}
	bool incir[N];
	inline int dfs(int u, int flow){
		if(u==T||!flow)return flow;assert(!incir[u]);int tot=0;incir[u]=1;
		for(register int &i=cur[u];i;i=nxt[i])if(cap[i]&&dis[u]==dis[to[i]]+val[i]&&!incir[to[i]]){
			int tmp=dfs(to[i],min(flow,cap[i]));
			cap[i]-=tmp;cap[i^1]+=tmp;tot+=tmp;flow-=tmp;if(!flow)break;
		}
		incir[u]=0;return tot;
	}
	inline ll solve(int need){//ÈÏÎª·ÑÓÃÔÚintÄÚ
		ll res=0;int c=0;
		while(spfa()){
			memcpy(cur,head,4*(T+2));
			int qaq=dfs(S,inf);c+=qaq;res+=qaq*dis[S];
		}
		return -(c==need?res:0);
	}
//}

int main() {
	read(n);
	rep(i,1,n)read(A[i]),read(B[i]),read(C[i]);
	int m;read(m);
	rep(i,1,m){
		char t[5];scanf("%s",t);
		D[i]=t[0],read(E[i]),read(F[i]);
	}
	rep(k,1,n){
		edgenum=1;rep(i,0,T)head[i]=0;S=2*k+n*2+5;T=S+1;
		rep(i,1,n)add(2*k+i,2*k+n+i,1,C[i]);
		static int l[N],r[N];
		//x
		rep(i,1,k)l[i]=0,r[i]=1e9;
		rep(i,1,m)
			if(D[i]=='L'){
				umax(l[F[i]+1],E[i]+1);
			}
			else if(D[i]=='R'){
				if(k-F[i]>=1)umin(r[k-F[i]],E[i]-1);
			}
		rep(i,2,k)umax(l[i],l[i-1]);
		per(i,k-1,1)umin(r[i],r[i+1]);
	//	rep(i,1,k)cerr<<l[i]<<' '<<r[i]<<endl;
		rep(i,1,k){
			add(S,i,1,0);
			rep(j,1,n)if(A[j]>=l[i]&&A[j]<=r[i])
				add(i,2*k+j,1,0);
		}
		//y
		rep(i,1,k)l[i]=0,r[i]=1e9;
		rep(i,1,m)
			if(D[i]=='D'){
				umax(l[F[i]+1],E[i]+1);
			}
			else if(D[i]=='U'){
				if(k-F[i]>=1)umin(r[k-F[i]],E[i]-1);
			}
		rep(i,2,k)umax(l[i],l[i-1]);
		per(i,k-1,1)umin(r[i],r[i+1]);
		rep(i,1,k){
			add(k+i,T,1,0);
			rep(j,1,n)if(B[j]>=l[i]&&B[j]<=r[i])
				add(2*k+n+j,k+i,1,0);
		}
		ll tmp=solve(k);umax(res,tmp);
	//	cerr<<"qwq "<<k<<' '<<tmp<<endl;
	}
	cout<<res;
	return 0;
}


Measured memory_bytes: 640