#include<bits/stdc++.h>
#define ll long long
#define FIO "agc31E"
using namespace std;

const int N=85,M=325,V=1e5,E=4e6,INF=1e9;

template<class T>inline void chkmax(T &a,const T &b){if(a<b)a=b;}
template<class T>inline void chkmin(T &a,const T &b){if(a>b)a=b;}

int n,m;
int x[N],y[N];
ll v[N];
int a[M],b[M];
char t[M][2];

int maxflow;
ll maxcost;

int ptr;
int h[V],to[E],nxt[E],flow[E],ecnt,hh[V];
ll cost[E];

inline void adde(int u,int v,int w,ll x){nxt[++ecnt]=h[u];h[u]=ecnt;to[ecnt]=v;flow[ecnt]=w;cost[ecnt]=x;}

inline void add(int u,int v,int w,ll x){adde(u,v,w,x);adde(v,u,0,-x);}

int lef[N],rig[N],id[N][2],S,T,low[N][2],hig[N][2];

int vis[V];
ll dis[V];

inline void build(int k){
  memset(h,0,sizeof h);
  ecnt=1;
  ptr=0;
  for(int i=1;i<=n;i++){
    id[i][0]=++ptr;
    id[i][1]=++ptr;
    add(id[i][0],id[i][1],1,v[i]);
  }
  for(int i=1;i<=k;i++)
    lef[i]=++ptr,rig[i]=++ptr;
  T=++ptr;
  for(int i=1;i<=k;i++)low[i][0]=low[i][1]=1,hig[i][0]=hig[i][1]=100;

  for(int i=1;i<=m;i++){
    switch(t[i][0]){
      case 'L':{
                 if(b[i]<k)
                   chkmax(low[b[i]+1][0],a[i]+1);
                 break;
               }
      case 'R':{
                 if(b[i]<k)
                   chkmin(hig[k-b[i]][0],a[i]-1);
                 break;
               }
      case 'D':{
                 if(b[i]<k)
                   chkmax(low[b[i]+1][1],a[i]+1);
                 break;
               }
      case 'U':{
                 if(b[i]<k)
                   chkmin(hig[k-b[i]][1],a[i]-1);
                 break;
               }
    }
  }

  for(int i=2;i<=k;i++)
    chkmax(low[i][0],low[i-1][0]),
    chkmax(low[i][1],low[i-1][1]);

  for(int i=k-1;i;i--)
    chkmin(hig[i][0],hig[i+1][0]),
    chkmin(hig[i][1],hig[i+1][1]);

  //for(int i=1;i<=k;i++) printf("rk %d x[%d,%d] y[%d][%d]\n",i,low[i][0],hig[i][0],low[i][1],hig[i][1]);

  for(int i=1;i<=k;i++)
    for(int j=1;j<=n;j++){
      if(x[j]>=low[i][0]&&x[j]<=hig[i][0])
        add(lef[i],id[j][0],1,0);
      if(y[j]>=low[i][1]&&y[j]<=hig[i][1])
        add(id[j][1],rig[i],1,0);
    }

  for(int i=1;i<=k;i++)add(S,lef[i],1,0),add(rig[i],T,1,0);

}

inline bool spfa(){
  memset(vis,0,sizeof vis);
  memset(dis,-0x3f,sizeof dis);
  dis[S]=0;
  queue<int>q;
  q.push(S);
  vis[S]=1;
  while(!q.empty()){
    int u=q.front();q.pop();
    //printf("u=%d\n",u);
    vis[u]=0;
    for(int i=h[u],v;i;i=nxt[i])if(dis[v=to[i]]<dis[u]+cost[i]&&flow[i]){
      dis[v]=dis[u]+cost[i];
      if(!vis[v]){
        q.push(v);
        vis[v]=1;
      }
    }
  }
  //printf("dis[T]=%lld dis[ptr+1]=%lld\n",dis[T],dis[ptr+1]);
  return dis[T]>dis[ptr+1];
}

inline int dfs(int u=S,int lim=INF){
  if(u==T)return lim;
  int ret=0;
  vis[u]=1;
  for(int &i=hh[u],v;i;i=nxt[i])if(dis[v=to[i]]==dis[u]+cost[i]&&flow[i]&&!vis[v]){
    int del=dfs(v,min(lim-ret,flow[i]));
    if(del){
      ret+=del;
      flow[i]-=del;
      flow[i^1]+=del;
      if(ret==lim)return ret;
    }
  }
  vis[u]=0;
  return ret;
}

inline void mcmf(){
  maxflow=maxcost=0;
  while(spfa()){
    memset(vis,0,sizeof vis);
    memcpy(hh,h,sizeof h);
    int f=dfs();
    maxflow+=f;
    //printf("mf+=%lld*%d\n",dis[T],f);
    maxcost+=dis[T]*f;
  }
  //printf("mf=%d mc=%lld\n",maxflow,maxcost);
}

ll ans;
int main(){
  scanf("%d",&n);
  for(int i=1;i<=n;i++)scanf("%d%d%lld",&x[i],&y[i],&v[i]);
  scanf("%d",&m);
  for(int i=1;i<=m;i++)scanf("%s%d%d",t[i],&a[i],&b[i]);

  for(int i=1;i<=n;i++){
    build(i);
    mcmf();
    if(maxflow==i)chkmax(ans,maxcost);
  }
  printf("%lld\n",ans);

  return 0;
}


Measured memory_bytes: 12032