//2019.5.25 by ljz
#include<bits/stdc++.h>
using namespace std;
#define res register int
#define LL long long
#define inf 0x3f3f3f3f
#define INF 1000000000000000LL
#define eps 1e-10
#define RG register
#define db double
#define pc(x) __builtin_popcount(x)
typedef pair<int,int> Pair;
#define mp make_pair
#define fi first
#define se second
#define gc getchar
//inline char gc() {
//    static char buf[100000],*p1,*p2;
//    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
//}
inline int read() {
    res s=0,ch=gc();
    while(ch<'0'||ch>'9')ch=gc();
    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
    return s;
}
inline LL Read() {
    RG LL s=0;
    res ch=gc();
    while(ch<'0'||ch>'9')ch=gc();
    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
    return s;
}
inline void swap(res &x,res &y) {
    x^=y^=x^=y;
}
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N=4e2+10;
namespace MAIN {
    int n,m;
    char str[10];
    LL v[N];
    int x[N],y[N],t[N],a[N],b[N];
    struct E{
        int next,to,flow;
        LL cost;
        E() {}
        E(res next,res to,res flow,RG LL cost):next(next),to(to),flow(flow),cost(cost) {}
    }edge[N*N];
    int head[N],cnt;
    inline void addedge(const res &u,const res &v,const res &f,const RG LL &c){
        edge[++cnt]=E(head[u],v,f,c),head[u]=cnt;
        edge[++cnt]=E(head[v],u,0,-c),head[v]=cnt;
    }
    LL dis[N];
    int Q[N*N],he,ta,S,T,vis[N],pre[N];
    inline bool spfa(RG LL &ret){
        for(res i=S;i<=T;i++)dis[i]=INF;
        Q[he=ta=1]=S,vis[S]=1,dis[S]=0;
        while(he<=ta){
            res u=Q[he++];
            vis[u]=0;
            for(res i=head[u];~i;i=edge[i].next){
                res tox=edge[i].to;
                if(dis[tox]>dis[u]+edge[i].cost&&edge[i].flow){
                    dis[tox]=dis[u]+edge[i].cost,pre[tox]=i;
                    if(!vis[tox])vis[tox]=1,Q[++ta]=tox;
                }
            }
        }
        if(dis[T]==INF)return 0;
        ret+=dis[T];
        for(res i=T;i!=S;i=edge[pre[i]^1].to)edge[pre[i]].flow--,edge[pre[i]^1].flow++;
        return 1;
    }
    int L[N],R[N],D[N],U[N];
    inline LL calc(const res &k){
        for(res i=1;i<=k;i++)L[i]=D[i]=0,R[i]=U[i]=inf;
        for(res i=1;i<=m;i++)
            if(b[i]<k){
                if(t[i]==0)L[b[i]+1]=a[i]+1;
                if(t[i]==1)R[k-b[i]]=a[i]-1;
                if(t[i]==2)D[b[i]+1]=a[i]+1;
                if(t[i]==3)U[k-b[i]]=a[i]-1;
            }
        for(res i=2;i<=k;i++)L[i]=max(L[i],L[i-1]),D[i]=max(D[i],D[i-1]);
        for(res i=k-1;i;i--)R[i]=min(R[i],R[i+1]),U[i]=min(U[i],U[i+1]);
        S=0,T=(n+k)<<1|1;
        for(res i=S;i<=T;i++)head[i]=-1;
        cnt=-1;
        for(res i=1;i<=n;i++)addedge(i,i+n,1,-v[i]-INF);
        for(res i=1;i<=k;i++){
            addedge(S,i+n*2,1,0),addedge(i+k+n*2,T,1,0);
            for(res j=1;j<=n;j++){
                if(L[i]<=x[j]&&x[j]<=R[i])addedge(i+n*2,j,1,0);
                if(D[i]<=y[j]&&y[j]<=U[i])addedge(j+n,i+k+n*2,1,0);
            }
        }
        RG LL ret=0;
        while(spfa(ret));
        return -ret-INF*k;
    }
    LL ans;
    inline int get(const RG char *st){
        return st[0]=='L'?0:(st[0]=='R'?1:(st[0]=='D'?2:3));
    }
    inline void MAIN(){
        n=read();
        for(res i=1;i<=n;i++)x[i]=read(),y[i]=read(),v[i]=Read();
        m=read();
        for(res i=1;i<=m;i++)scanf("%s",str),t[i]=get(str),a[i]=read(),b[i]=read();
        for(res i=1;i<=n;i++)ans=max(ans,calc(i));
        printf("%lld\n",ans);
    }
}
int main() {
//    srand((unsigned)time(NULL));
//    freopen("zao.in","r",stdin);
//    freopen("std.out","w",stdout);
    MAIN::MAIN();
    return 0;
}

Measured memory_bytes: 768