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

const int64_t INF = 1e18;
struct MinCostFlow{
    struct edge {
        int64_t to, cap, cost, rev;
        edge(int64_t to, int64_t cap, int64_t cost, int64_t rev):to(to), cap(cap), cost(cost), rev(rev){}
    };

    int N, S, T;
    int64_t flow;
    int64_t cost;
    vector<vector<edge>> G;
    vector<pair<int, int>> prv; // {v, e};
    vector<int64_t> h;

    MinCostFlow(int N, int S, int T):N(N), S(S), T(T){
        flow = cost = 0;
        G.resize(N);
        prv.resize(N);
        h.resize(N);
    }

    void add_edge(int64_t from, int64_t to, int64_t cap, int64_t cost){
        G[from].emplace_back(to, cap, cost, G[to].size());
        G[to].emplace_back(from, 0, -cost, G[from].size()-1);
    }

    int64_t calculate(int64_t f){
        typedef pair<int64_t, int> P;
        
        int64_t res = 0;
        vector<int64_t> dist(N);

        while(f > flow){
            priority_queue<P, vector<P>, greater<P>> que;
            fill(dist.begin(), dist.end(), INF);
            dist[S] = 0;
            que.push({0, S});
            while(que.size()){
                auto p = que.top(); que.pop();
                int64_t d = p.first;
                int i = p.second;
                if(d > dist[i]) continue;
                for(int idx=0; idx<G[i].size(); idx++){
                    auto& e = G[i][idx];
                    int j = e.to;
                    int64_t d2 = d + e.cost + h[i] - h[j];
                    if(e.cap > 0 && dist[j] > d2){
                        dist[j] = d2;
                        prv[j] = {i, idx};
                        que.push({dist[j], j});
                    }
                }
            }
            if(dist[T] == INF) return -1;
            for(int i=0; i<N; i++) h[i] += dist[i];
            
            int64_t d = f - flow;
            for(int i=T; i!=S; i=prv[i].first){
                auto& e = G[prv[i].first][prv[i].second];
                d = min(d, e.cap);
            }
            flow += d;
            res += d * h[T];
            for(int i=T; i!=S; i=prv[i].first){
                auto& e = G[prv[i].first][prv[i].second];
                e.cap -= d;
                G[i][e.rev].cap += d;
            }
        } 
        return res;
    }
};

void chmin(int& a, int b){
    a = min(a, b);
}
void chmax(int& a, int b){
    a = max(a, b);
}

int N, M, X[80], Y[80];
int64_t V[80];
vector<pair<int, int>> C[4];

int64_t solve(int K){
    vector<vector<int>> L(2, vector<int>(K, 1)), R(2, vector<int>(K, 100));
    for(int t=0; t<2; t++){
        for(auto& p : C[2*t]){
            int a = p.first, b = p.second;
            if(b < K) chmax(L[t][b], a+1);
        }
        for(auto& p : C[2*t+1]){
            int a = p.first, b = p.second;
            if(b < K) chmin(R[t][K-b-1], a-1);
        }
        for(int i=1; i<K; i++) chmax(L[t][i], L[t][i-1]);
        for(int i=K-2; i>=0; i--) chmin(R[t][i], R[t][i+1]);
    }

    int S = 320, T = 321;
    MinCostFlow solver(T+1, S, T);
    for(int i=0; i<K; i++){
        solver.add_edge(S, i, 1, 0);
        for(int j=0; j<N; j++){
            if(L[0][i] <= X[j] && X[j] <= R[0][i]) solver.add_edge(i, 80+j, 1, 0);
            if(L[1][i] <= Y[j] && Y[j] <= R[1][i]) solver.add_edge(160+j, 240+i, 1, 0);
        }
        solver.add_edge(240+i, T, 1, 0);
    }
    const int64_t OFFSET = 1e15;
    for(int i=0; i<N; i++) solver.add_edge(80+i, 160+i, 1, OFFSET - V[i]);

    int64_t res = solver.calculate(K);
    return (res == -1 ? -1 : K*OFFSET - res);
}

int main(){
    cin >> N;
    for(int i=0; i<N; i++) cin >> X[i] >> Y[i] >> V[i];
    cin >> M;
    const string LRDU = "LRDU";
    for(int i=0; i<M; i++){
        char t;
        int a, b;
        cin >> t >> a >> b;
        C[LRDU.find(t)].push_back({a, b});
    }

    int64_t ans = 0;
    for(int K=1; K<=N; K++) ans = max(ans, solve(K));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1228