#include<bits/stdc++.h>
using namespace std;
#define int ll
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define Rep(i,a,b) for(register int i=(a);i<=int(b);++i)
#define Dep(i,a,b) for(register int i=(a);i>=int(b);--i)
#define rep(i,a,b) for(register int i=(a);i<int(b);++i)
#define mem(x,v) memset(x,v,sizeof(x))
#define fi first
#define se second
#define gc getchar
#define pc putchar
inline ll read(){
    ll x=0,f=1;char c=gc();
    for(;!isdigit(c);c=gc())if(c=='-')f=-1;
    for(;isdigit(c);c=gc())x=(x<<1)+(x<<3)+(c^48);
    return x*f;
}
inline void write(ll x){if(x<0)x=-x,pc('-');if(x>=10)write(x/10);putchar(x%10+'0');}
inline void wri(ll x){write(x);pc(' ');}
inline void writeln(ll x){write(x);pc('\n');}
const int maxn = 2005;
struct Edge{
	int to,nxt,cap;
	ll v;
	Edge(){}
	Edge(int to,int nxt,int cap,ll v):
		to(to),nxt(nxt),cap(cap),v(v){}
}edge[maxn*maxn];
int first[maxn],nume;
int tot,S,T,idx[maxn],idy[maxn];
void Addedge(int a,int b,int c,ll v){
//	printf("_%d -> %d{%d %d}\n",a,b,c,v);
	edge[nume] = Edge(b,first[a],c,v);first[a] = nume++;
	edge[nume] = Edge(a,first[b],0,-v);first[b] = nume++;
}
ll dis[maxn];
int q[maxn*maxn],vis[maxn],from[maxn];
bool spfa(){
	Rep(i,1,tot) dis[i] = -(1ll<<62),vis[i] = 0,from[i] = -1;
	int front=0,rear=0;
	q[rear++] = S;dis[S] = 0;vis[S] = true;
	while(front < rear){
		int u = q[front++];vis[u] = false;
		for(int e=first[u];~e;e=edge[e].nxt){
			if(dis[edge[e].to] < dis[u] + edge[e].v && edge[e].cap){
				dis[edge[e].to] = dis[u] + edge[e].v;
				from[edge[e].to] = e;
				if(!vis[edge[e].to]){
					vis[edge[e].to] = true;
					q[rear++] = edge[e].to;
				}
			}
		}
	}
	return dis[T] != -(1ll<<62);
}
void del(){
	for(int e=from[T];~e;e=from[edge[e^1].to]){
		edge[e].cap--,edge[e^1].cap++;
	}
}
struct que{
	char s[10];
	int x,cnt;
}qq[maxn];
int n,Q,x[maxn],y[maxn],mn[maxn],mx[maxn];
ll v[maxn];
const int MX = 100;
ll work(int cnt){
	memset(first,-1,sizeof(first));nume = 0;
	tot = 0;S = ++tot;T = ++tot;
	Rep(i,1,MX) idx[i] = ++tot,idy[i] = ++tot;
	Rep(i,1,n) Addedge(idx[x[i]],idy[y[i]],1,v[i]);
	
		Rep(i,0,cnt+1) mx[i]=MX,mn[i]=1;
		Rep(i,1,Q){
			if (qq[i].s[0]=='L'&&cnt>=qq[i].cnt+1)
				mn[qq[i].cnt+1]=max(mn[qq[i].cnt+1],qq[i].x+1);
			if (qq[i].s[0]=='R'&&cnt>=qq[i].cnt+1)
				mx[cnt-qq[i].cnt]=min(mx[cnt-qq[i].cnt],qq[i].x-1);
		}
		Rep(i,1,cnt) mn[i]=max(mn[i],mn[i-1]);
		Dep(i,cnt,1) mx[i]=min(mx[i],mx[i+1]);
		Rep(i,1,cnt){
			int tmp=++tot;
			if (mn[i]>mx[i]) return 0;
			Addedge(S,tmp,1,0);
			Rep(j,mn[i],mx[i])
				Addedge(tmp,idx[j],1,0);
		}

		Rep(i,0,cnt+1) mx[i]=MX,mn[i]=1;
		Rep(i,1,Q){
			if (qq[i].s[0]=='D'&&cnt>=qq[i].cnt+1)
				mn[qq[i].cnt+1]=max(mn[qq[i].cnt+1],qq[i].x+1);
			if (qq[i].s[0]=='U'&&cnt>=qq[i].cnt+1)
				mx[cnt-qq[i].cnt]=min(mx[cnt-qq[i].cnt],qq[i].x-1);
		}
		Rep(i,1,cnt) mn[i]=max(mn[i],mn[i-1]);
		Dep(i,cnt,1) mx[i]=min(mx[i],mx[i+1]);
		Rep(i,1,cnt){
			int tmp=++tot;
			if (mn[i]>mx[i]) return 0;
			Addedge(tmp,T,1,0);
			Rep(j,mn[i],mx[i])
				Addedge(idy[j],tmp,1,0);
		}
	ll ans = 0;
	Rep(i,1,cnt){
		if(!spfa()) return 0;
		ans += dis[T]; del();
	}
	return ans;
}
signed main(){
	scanf("%d",&n);
	Rep(i,1,n) scanf("%d%d%lld",&x[i],&y[i],&v[i]);
	scanf("%d",&Q);
	Rep(i,1,Q) scanf("%s%d%d",qq[i].s,&qq[i].x,&qq[i].cnt);
	ll ans = 0;
	Rep(i,1,n) ans=max(ans,work(i));
	writeln(ans);
	return 0;
}

Measured memory_bytes: 2304