/*

  _|_|                              _|  _|    _|
_|    _|  _|  _|_|  _|_|_|_|        _|  _|  _|
_|    _|  _|_|          _|          _|  _|_|
_|    _|  _|          _|      _|    _|  _|  _|
  _|_|    _|        _|_|_|_|    _|_|    _|    _|

*/
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
#include<queue>
#include<set>
//#define ls (rt<<1)
//#define rs (rt<<1|1)
#define vi vector<int>
#define pb push_back
#define mk make_pair
#define pii pair<ll,ll>
#define rep(i,a,b) for(int i=(a),i##end=(b);i<=i##end;i++)
#define fi first
#define se second
#define int long long
typedef long long ll;
using namespace std;
const int maxn=420;
const int inf=1e18+100;
int xl[maxn],xr[maxn],yl[maxn],yr[maxn],s=415,t=416;
int head[maxn],cnt=1;
struct gg{
    int u,v,w;ll cost;int next;
    void insert(int U,int V,int W,ll Cost,int Next){
        u=U,v=V,w=W,cost=Cost,next=Next;
    }
}side[(maxn*maxn)*2];
struct Point{
    int x,y;
    ll cost=0;
}point[maxn];
struct Lim{
    int a,b;char c;
}lim[maxn];
void ins(int u,int v,int w,ll cost){
    side[++cnt].insert(u,v,w,cost,head[u]);head[u]=cnt;
    side[++cnt].insert(v,u,0,-cost,head[v]);head[v]=cnt;
}
int n,m;
void init(int k){
    rep(i,1,k)xl[i]=yl[i]=-inf,xr[i]=yr[i]=inf;
    rep(i,1,m){
        if(lim[i].c=='L')rep(j,lim[i].b+1,k)xl[j]=max(xl[j],lim[i].a+1);
        else if(lim[i].c=='R')for(int j=k-lim[i].b;j>0;j--)xr[j]=min(xr[j],lim[i].a-1);
        else if(lim[i].c=='D')rep(j,lim[i].b+1,k)yl[j]=max(yl[j],lim[i].a+1);
        else if(lim[i].c=='U')for(int j=k-lim[i].b;j>0;j--)yr[j]=min(yr[j],lim[i].a-1);
    }
    memset(head,0,sizeof(head));cnt=1;
    rep(i,1,k)ins(s,2*n+i,1,0);
    rep(i,1,k)ins(2*n+k+i,t,1,0);
    rep(i,1,n){
        ins(i,n+i,1,point[i].cost);
        rep(j,1,k){
            if(xl[j]<=point[i].x&&point[i].x<=xr[j])ins(2*n+j,i,1,0);
            if(yl[j]<=point[i].y&&point[i].y<=yr[j])ins(n+i,2*n+k+j,1,0);
        }
    }
}
int q[maxn*30];
ll dis[maxn],lenth;
bool vis[maxn];
bool spfa(){
    rep(i,1,maxn-1)dis[i]=-inf;
    memset(vis,0,sizeof(vis));
    int hd=1,tl=1;q[hd]=s;vis[s]=1;dis[s]=0;
    while(hd<=tl){
        int u=q[hd++];vis[u]=0;//cout<<u<<' '<<endl;
        for(int i=head[u];i;i=side[i].next){
            int v=side[i].v;if(!side[i].w)continue;
            if(dis[u]+side[i].cost>dis[v]){
                dis[v]=dis[u]+side[i].cost;
                if(!vis[v])q[++tl]=v;
                vis[v]=1;
            }
        }
    }
    if(dis[t]!=-inf)return 1;
    return 0;
}
int dfs(int u,int flow){
    if(u==t)return flow;
    vis[u]=1;int tot=0;
    for(int i=head[u];i;i=side[i].next){
        int v=side[i].v;if(vis[v]||!side[i].w||dis[v]!=dis[u]+side[i].cost)continue;
        int sent=dfs(v,min(flow,side[i].w));
        lenth+=1ll*side[i].cost*sent,side[i].w-=sent,side[i^1].w+=sent,tot+=sent;flow-=sent;
    }
    // vis[u]=0;
    return tot;
}
pii dinic(){
    int mxflow=0;lenth=0;
    while(spfa()){
        int x;
        while((x=dfs(s,inf)))mxflow+=x;
    }
    return mk(mxflow,lenth);
}
char tmp[3];
signed main(){
    scanf("%lld",&n);
    rep(i,1,n)scanf("%lld%lld%lld",&point[i].x,&point[i].y,&point[i].cost);
    scanf("%lld",&m);
    rep(i,1,m){
        scanf("%s%lld%lld",tmp+1,&lim[i].a,&lim[i].b);lim[i].c=tmp[1];
    }
    ll out=0;
    rep(k,1,n){
        init(k);
        pii ans=dinic();out=max(out,ans.se);//cout<<ans.se<<endl;
    }
    cout<<out;
    return 0;
}


Measured memory_bytes: 4464