#include<cstdio>
#include<cstring>
#include<queue>
#define int long long
using namespace std;
const int INF=0x3f3f3f3f;
typedef long long ll;
int n,m,s,t;
ll ans,Ans,dist[350];
int maxflow,vis[350];
int edgenum,W[26500],V[26500],Next[26500],F[26500],Head[350];
int lx[350],rx[350],ly[350],ry[350];
struct node{ int x,y,v;} p[350];
struct node2{ int t,a,b;} q[350];
char Getchar(){
    static char now[1<<20],*S,*T;
    if (T==S){
        T=(S=now)+fread(now,1,1<<20,stdin);
        if (T==S) return EOF;
    }
    return *S++;
}
int read(){
    int x=0,f=1;
    char ch=Getchar();
    while (ch<'0'||ch>'9'){
        if (ch=='-') f=-1;
        ch=Getchar();
    }
    while (ch<='9'&&ch>='0') x=x*10+ch-'0',ch=Getchar();
    return x*f;
}
char readop(){
    char ch=Getchar();
    while (ch<'A'||ch>'Z') ch=Getchar();
    return ch;
}
void addedge(int u,int v,int w,int f){
    V[++edgenum]=v; F[edgenum]=f; W[edgenum]=w;
    Next[edgenum]=Head[u];
    Head[u]=edgenum;
}
void Addedge(int u,int v,int w,int f){
//	printf("%d %d %d %d\n",u,v,w,f);
    addedge(u,v,w,f);
    addedge(v,u,0,-f);
}
bool spfa(){
    memset(vis,false,sizeof(vis));
    memset(dist,0x3f,sizeof(dist));
    dist[s]=0;
    vis[s]=true;
    queue<int> que;
    que.push(s);
    while (!que.empty()){
        int u=que.front(); que.pop();
        vis[u]=false;
        for (int e=Head[u];e;e=Next[e]){
            int d=V[e];
            if (dist[d]>dist[u]+F[e]&&W[e]){
                dist[d]=dist[u]+F[e];
                if (!vis[d]){
                    que.push(d);
                    vis[d]=true;
                }
            }
        }
    }
    return dist[t]<INF;
}
int dfs(int u,int flow){
    if (u==t){ 
        vis[t]=true; maxflow+=flow;
        return flow;
    }
    int used=0;
    vis[u]=true;
    for (int e=Head[u];e;e=Next[e]){
        int d=V[e];
        if ((!vis[d]||d==t)&&W[e]&&dist[d]==dist[u]+F[e]){
            int minflow=dfs(d,min(flow-used,W[e]));
            if (minflow!=0) ans+=F[e]*minflow,W[e]-=minflow,W[e^1]+=minflow,used+=minflow;
            if (used==flow) break;
        }
    }
    return used;
}
void mincostmaxflow(){
	ans=0; maxflow=0;
    while (spfa()){
        vis[t]=1;
        while (vis[t]){
            memset(vis,false,sizeof(vis));
            dfs(s,INF); 
        }
    }
}
void solve(int k){
	edgenum=1; memset(Head,0,sizeof(Head));
	s=k+n+n+k+1; t=s+1;
	for (int i=1;i<=k;i++) Addedge(s,i,1,0),Addedge(k+n+n+i,t,1,0);
	for (int i=1;i<=n;i++) Addedge(k+i,k+n+i,1,-p[i].v);
    for (int i=1;i<=k;i++) lx[i]=0,ly[i]=0,rx[i]=INF,ry[i]=INF;
	for (int i=1;i<=m;i++)
		switch (q[i].t){
			case 'U': for (int j=1;j<=k-q[i].b;j++) ry[j]=min(ry[j],q[i].a-1); break;
			case 'D': for (int j=q[i].b+1;j<=k;j++) ly[j]=max(ly[j],q[i].a+1); break;
			case 'L': for (int j=q[i].b+1;j<=k;j++) lx[j]=max(lx[j],q[i].a+1); break;
			case 'R': for (int j=1;j<=k-q[i].b;j++) rx[j]=min(rx[j],q[i].a-1); break;
		}
    for (int i=1;i<=k;i++)
		for (int j=1;j<=n;j++)
			if (lx[i]<=p[j].x&&p[j].x<=rx[i]) Addedge(i,k+j,1,0);
    for (int i=1;i<=k;i++)
		for (int j=1;j<=n;j++)
			if (ly[i]<=p[j].y&&p[j].y<=ry[i]) Addedge(k+n+j,k+n+n+i,1,0);
	mincostmaxflow(); Ans=max(Ans,-ans);
}
signed main(){
	n=read();
	for (int i=1;i<=n;i++){
		p[i].x=read();
		p[i].y=read();
		p[i].v=read();
	}
	m=read();
	for (int i=1;i<=m;i++){
		q[i].t=readop();
		q[i].a=read();
		q[i].b=read();
	}
	for (int k=1;k<=n;k++) solve(k);
	printf("%lld\n",Ans);
	return 0;
}


Measured memory_bytes: 896