#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
#define ll long long
ll gi(){
    ll x=0,w=1;char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
    if(ch=='-')w=0,ch=getchar();
    while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
    return w?x:-x;
}
int gc(){
    char ch=getchar();
    while(ch<'A'||ch>'Z')ch=getchar();
    return ch;
}
const int N=405;
struct edge{int to,nxt,w;ll cost;}E[N*N];
int n,m,x[N],y[N],t[N],a[N],b[N],L[N],R[N],D[N],U[N],head[N],cnt,S,T,vis[N],pe[N];
ll v[N],dis[N],ans;queue<int>Q;
void link(int u,int v,ll w){
    E[++cnt]=(edge){v,head[u],1,w};head[u]=cnt;
    E[++cnt]=(edge){u,head[v],0,-w};head[v]=cnt;
}
bool spfa(ll &res){
    memset(dis,63,sizeof(dis));
    dis[S]=0;Q.push(S);
    while(!Q.empty()){
        int u=Q.front();Q.pop();vis[u]=0;
        for(int i=head[u],v;i;i=E[i].nxt)
            if(E[i].w&&dis[v=E[i].to]>dis[u]+E[i].cost){
                dis[v]=dis[u]+E[i].cost;pe[v]=i;
                if(!vis[v])vis[v]=1,Q.push(v);
            }
    }
    if(dis[T]==dis[0])return false;res+=dis[T];
    for(int i=T;i!=S;i=E[pe[i]^1].to)--E[pe[i]].w,++E[pe[i]^1].w;
    return true;
}
ll cal(int k){
    for(int i=1;i<=k;++i)L[i]=D[i]=0,R[i]=U[i]=233;
    for(int i=1;i<=m;++i)
        if(b[i]<k){
            if(t[i]=='L')L[b[i]+1]=a[i]+1;
            if(t[i]=='R')R[k-b[i]]=a[i]-1;
            if(t[i]=='D')D[b[i]+1]=a[i]+1;
            if(t[i]=='U')U[k-b[i]]=a[i]-1;
        }
    for(int i=2;i<=k;++i)L[i]=max(L[i],L[i-1]),D[i]=max(D[i],D[i-1]);
    for(int i=k-1;i;--i)R[i]=min(R[i],R[i+1]),U[i]=min(U[i],U[i+1]);
    memset(head,0,sizeof(head));cnt=1;S=n+k<<1|1;T=n+k+1<<1;
    for(int i=1;i<=n;++i)link(i,n+i,-v[i]-1000000000000000ll);
    for(int i=1;i<=k;++i){
        link(S,n+n+i,0);link(n+n+k+i,T,0);
        for(int j=1;j<=n;++j){
            if(L[i]<=x[j]&&x[j]<=R[i])link(n+n+i,j,0);
            if(D[i]<=y[j]&&y[j]<=U[i])link(n+j,n+n+k+i,0);
        }
    }
    ll res=0;while(spfa(res));return -res-1000000000000000ll*k;
}
int main(){
    n=gi();
    for(int i=1;i<=n;++i)x[i]=gi(),y[i]=gi(),v[i]=gi();
    m=gi();
    for(int i=1;i<=m;++i)t[i]=gc(),a[i]=gi(),b[i]=gi();
    for(int i=1;i<=n;++i)ans=max(ans,cal(i));
    printf("%lld\n",ans);return 0;
}
