#include<bits/stdc++.h>
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define fi first
#define se second
#define sz(a) int(a.size())
#define clr(a) memset(a,0,sizeof(a))
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
const int inf=1e9;
const ll Inf=1e18;
const int mod=1;
template<typename T=int>
T gi() {
	T x=0,o=1;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
	if(ch=='-') o=-1,ch=getchar();
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x*o;
}
template<typename T> bool chkmax(T &a,T b) { return a<b?a=b,1:0; };
template<typename T> bool chkmin(T &a,T b) { return a>b?a=b,1:0; };
int add(int a,int b) { return a+b>=mod?a+b-mod:a+b; }
int sub(int a,int b) { return a-b<0?a-b+mod:a-b; }
void inc(int &a,int b) { a=(a+b>=mod?a+b-mod:a+b); }
void dec(int &a,int b) { a=(a-b<0?a-b+mod:a-b); }
string to_string(string s) { return '"'+s+'"'; }
string to_string(const char *s) { return to_string((string)s); }
string to_string(bool b) { return (b?"true":"false"); }
template<typename A,typename B> string to_string(pair<A,B> p) {
	return "("+to_string(p.fi)+","+to_string(p.se)+")";
}
template<typename T> string to_string(T v) {
	int fst=1;string ret="{";
	for(auto x:v) {
		if(!fst) ret+=",";
		fst=0,ret+=to_string(x);
	}
	ret+="}";return ret;
}
void dbg_out() { cerr<<endl; }
template<typename Head,typename... Tail> void dbg_out(Head H,Tail... T) {
	cerr<<" "<<to_string(H);
	dbg_out(T...);
}
#define dbg(...) cerr<<"{"<<#__VA_ARGS__<<"}:",dbg_out(__VA_ARGS__)

template<typename T>
int qpow(int a,T b) {
	int ret=1;
	while(b) {
		if(b&1) ret=1ll*ret*a%mod;
		a=1ll*a*a%mod,b>>=1;
	}
	return ret;
}

const int N=1e5+10;

namespace mcmf {

	struct edge {
		int to,w,nxt;ll cost;
	} e[N<<1];

	int tot=1,h[N];
	
	void adde(int u,int v,int w,ll c) {
		e[++tot]=(edge){v,w,h[u],c};h[u]=tot;
		e[++tot]=(edge){u,0,h[v],-c};h[v]=tot;
	}

	int cur[N],s,t;
	ll dis[N],ans=0;
	bool vis[N];
	
	bool spfa() {
		memset(dis,0x3f,sizeof(dis));
		clr(vis);
		deque<int> q;q.pb(s);dis[s]=0;
		while(!q.empty()) {
			int u=q.front();q.pop_front();vis[u]=0;
			for(int i=h[u];i;i=e[i].nxt)
				if(e[i].w) {
					int v=e[i].to;
					if(chkmin(dis[v],dis[u]+e[i].cost)) {
						if(!vis[v]) vis[v]=1,e[i].cost<0?q.push_front(v):q.pb(v);
					}
				}
		}
		return dis[t]<Inf;
	}
	
	int dfs(int u,int flow) {
		if(u==t) return flow;
		vis[u]=1; int ret=0;
		for(int &i=cur[u];i;i=e[i].nxt) {
			int v=e[i].to;
			if(e[i].w&&dis[v]==dis[u]+e[i].cost&&!vis[v]) {
				int d=dfs(v,min(flow,e[i].w));
				e[i].w-=d;e[i^1].w+=d;ret+=d;flow-=d;ans+=e[i].cost*d;
				if(!flow) { vis[u]=0;break; }
			}
		}
		return ret;
	}

	pair<int,ll> solve() {
		ans=0;
		int ret=0;
		while(spfa()) {
			memcpy(cur,h,sizeof(h));
			ret+=dfs(s,inf);
		}
		return mp(ret,ans);
	}

	void init(int _s,int _t) {
		s=_s,t=_t;
		tot=1;memset(h,0,sizeof(h));
	}
	
}

char gc() {
	char ch=getchar();
	while(!isupper(ch)) ch=getchar();
	return ch;
}

int n,m,x[N],y[N],a[N],b[N],liml[N],limr[N],limu[N],limd[N];
ll v[N];
char c[N];

ll calc(int k) {
	int s=0,t=2*k+201;
	mcmf::init(s,t);
	for(int i=1;i<=k;i++) {
		liml[i]=1,limr[i]=100;
		limd[i]=1,limu[i]=100;
	}
	for(int i=1;i<=m;i++) {
		if(b[i]>=k) continue;
		if(c[i]=='L') {
			chkmax(liml[b[i]+1],a[i]+1);
		}
		else if(c[i]=='R') {
			chkmin(limr[k-b[i]],a[i]-1);
		}
		else if(c[i]=='D') {
			chkmax(limd[b[i]+1],a[i]+1);
		}
		else {
			chkmin(limu[k-b[i]],a[i]-1);
		}
	}
	for(int i=2;i<=k;i++) {
		chkmax(liml[i],liml[i-1]);
		chkmax(limd[i],limd[i-1]);
	}
	for(int i=k-1;i;i--) {
		chkmin(limr[i],limr[i+1]);
		chkmin(limu[i],limu[i+1]);
	}
	for(int i=1;i<=k;i++) {
		mcmf::adde(s,i,1,0);
		mcmf::adde(i+k+200,t,1,0);
		for(int j=liml[i];j<=limr[i];j++) {
			mcmf::adde(i,k+j,1,0);
		}
		for(int j=limd[i];j<=limu[i];j++) {
			mcmf::adde(k+100+j,k+200+i,1,0);
		}
	}
	for(int i=1;i<=n;i++) {
		mcmf::adde(k+x[i],k+100+y[i],1,-v[i]);
	}
	auto ret=mcmf::solve();
	if(ret.fi!=k) return -1;
	return -ret.se;
}

int main() {
	n=gi();
	for(int i=1;i<=n;i++) x[i]=gi(),y[i]=gi(),v[i]=gi<ll>();
	m=gi();
	for(int i=1;i<=m;i++) c[i]=gc(),a[i]=gi(),b[i]=gi();
	ll ans=0;
	for(int i=1;i<=n;i++) chkmax(ans,calc(i));
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 6400