#include<bits/stdc++.h>
using namespace std;

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
    ost<<"{"<<p.first<<","<<p.second<<"}";
    return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
    ost<<"{";
    for(int i=0;i<v.size();i++){
        if(i)ost<<",";
        ost<<v[i];
    }
    ost<<"}";
    return ost;
}

struct PrimalDual{
    using F=long long;
    static const F INF;
    
    struct Edge{
        int to;
        F cap,cost;
        int rev;
        Edge(int to,F cap,F cost,int rev):to(to),cap(cap),cost(cost),rev(rev){}
    };
    
    int n;
    vector<vector<Edge>>G;

    PrimalDual(int n):n(n),G(n){}

    void addEdge(int from,int to,F cap,F cost){
        G[from].push_back(Edge(to,cap,cost,G[to].size()));
        G[to].push_back(Edge(from,0,-cost,G[from].size()-1));
    }


    F minCostFlow(int s,int t,F f){
        F cur=0;

        vector<F>h(n);
        vector<int>prevv(n,-1),preve(n,-1);
        vector<F>dist(n);
        priority_queue<pair<F,int>,vector<pair<F,int>>,greater<pair<F,int>>>que;
        
        /*
        fill(h.begin(),h.end(),INF);
        h[s]=0;
        while(true){
            bool update=false;
            for(int v=0;v<n;v++){
                for(auto &e:G[v]){
                    if(e.cap&&h[e.to]>h[v]+e.cost){
                        update=true;
                        h[e.to]=h[v]+e.cost;
                    }
                }
            }
            if(!update)break;
        }
        */


        while(f>0){
            fill(dist.begin(),dist.end(),INF);
            dist[s]=0;
            que.emplace(0,s); 
            while(que.size()){
                F d;
                int v;
                tie(d,v)=que.top();
                que.pop();
                if(dist[v]<d)continue;
                for(int i=0;i<G[v].size();i++){
                    Edge &e=G[v][i];
                    F nd=dist[v]+e.cost+h[v]-h[e.to];
                    if(e.cap>0&&dist[e.to]>nd){
                        dist[e.to]=nd;
                        prevv[e.to]=v;preve[e.to]=i;
                        que.emplace(nd,e.to);
                    }
                }
            }
            if(dist[t]==INF)return INF;
            for(int v=0;v<n;v++)h[v]+=dist[v];
            F nf=f;
            for(int v=t;v!=s;v=prevv[v]){
                nf=min(nf,G[prevv[v]][preve[v]].cap);
            }
            f-=nf;
            cur+=nf*h[t];
            for(int v=t;v!=s;v=prevv[v]){
                Edge &e=G[prevv[v]][preve[v]];
                e.cap-=nf;
                G[v][e.rev].cap+=nf;
            }
        }
        return cur;
    }
};
const PrimalDual::F PrimalDual::INF=1ll<<50;

int N;
int X[111],Y[111],V[111];
int M;
char T[333];
int A[333],B[333];

const int LIM=1000000000000000;

int solve(int num){
    vint capX(100,PrimalDual::INF),capY(100,PrimalDual::INF);
    vint lowX(100),lowY(100);

    PrimalDual pd(200+4);
    int src=200;
    int snk=201;
    int supersrc=202;
    int supersnk=203;
    rep(i,M){
        if(T[i]=='U'){
            if(B[i]>num)continue;
            if(A[i]==0)continue;
            lowY[A[i]-1]=num-B[i];
        }
        if(T[i]=='D'){
            capY[A[i]]=B[i];
        }
        
        if(T[i]=='L'){
            capX[A[i]]=B[i];
        }
        
        if(T[i]=='R'){
            if(B[i]>num)continue;
            if(A[i]==0)continue;
            lowX[A[i]-1]=num-B[i];
        }
    }

    /*
    rep(i,100){
        if(capX[i]!=PrimalDual::INF)cout<<"capX "<<i<<" "<<capX[i]<<endl;
        if(lowX[i])cout<<"lowX "<<i<<" "<<lowX[i]<<endl;
    }
    rep(i,100){
        if(capY[i]!=PrimalDual::INF)cout<<"capY "<<i<<" "<<capY[i]<<endl;
        if(lowY[i])cout<<"lowY "<<i<<" "<<lowY[i]<<endl;
    }*/


    int f=num;

    rep(i,100){
        if(capX[i]<lowX[i])return 0;
        int from,to=i;
        if(i==99)from=src;
        else from=i+1;
        
        pd.addEdge(from,to,capX[i]-lowX[i],0);
        pd.addEdge(supersrc,to,lowX[i],0);
        pd.addEdge(from,supersnk,lowX[i],0);
        f+=lowX[i];
    }
    
    rep(i,100){
        if(capY[i]<lowY[i])return 0;
        int from=i+100,to;
        if(i==99)to=snk;
        else to=i+1+100;
        
        pd.addEdge(from,to,capY[i]-lowY[i],0);
        pd.addEdge(supersrc,to,lowY[i],0);
        pd.addEdge(from,supersnk,lowY[i],0);
        f+=lowY[i];
    }
    rep(i,N){
        pd.addEdge(X[i],Y[i]+100,1,LIM-V[i]);
    }
    pd.addEdge(supersrc,src,num,0);
    pd.addEdge(snk,supersnk,num,0);

    int tmp=pd.minCostFlow(supersrc,supersnk,f);
    if(tmp==PrimalDual::INF)return 0;
    tmp-=LIM*num;
    tmp*=-1;
    return tmp;
}

signed main(){
    scanf("%lld",&N);
    rep(i,N)scanf("%lld%lld%lld",&X[i],&Y[i],&V[i]),X[i]--,Y[i]--;

    scanf("%lld",&M);
    rep(i,M)scanf(" %c%lld%lld",&T[i],&A[i],&B[i]),A[i]--;



    int ans=0;
    for(int i=1;i<=N;i++)chmax(ans,solve(i));
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 384