#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<complex>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define INF (1<<29)
#define LINF (1LL<<60)
#define EPS (1e-10)
#define PI 3.1415926535897932384626433832795028
typedef long long Int;
typedef pair<Int, Int> P;
typedef long double Real;
typedef complex<Real> CP;

class Edge{
public:
    Int from, to, rev;
    Int cost, lim;
    Edge(Int from, Int to, Int cost, Int lim = -1, Int rev = -1):
        from(from),to(to),cost(cost),lim(lim),rev(rev){}
};


class Graph{
public:
    Int n;
    Int m;
    vector<vector<Edge>> edge;
    Graph(Int n = 0):n(n),m(0){
        edge = vector<vector<Edge>>(n);
    }
    void add_edge(Int from, Int to, Int cost = 1, Int lim = -1)
        {
            if(lim == -1){
                edge[from].push_back(Edge(from, to, cost));
                return;
            }
            edge[from].push_back(Edge(from, to, cost, lim, edge[to].size()));
            edge[to].push_back(Edge(to, from, -cost, 0, edge[from].size() - 1));
        }
};

class MinCostFlow{
public:
    priority_queue<P, vector<P>, greater<P> > pq;
    vector<Int> dist;
    vector<Int> before;
    vector<Int> index;
    vector<Int> potential;
    MinCostFlow(){}
    
    void Dijkstra(Graph &g, Int s){
        fill(dist.begin(), dist.end(), LINF);
        pq.push(P(0, s));
        dist[s] = 0;

        while(!pq.empty()){
            P tmp = pq.top();pq.pop();
            Int from = tmp.second;
            if(tmp.first > dist[from])continue;
            for(Int i = 0;i < g.edge[from].size();i++){
                auto e = g.edge[from][i];
                auto cost = e.cost + potential[e.from] - potential[e.to];
                if(e.lim == 0)continue;
                if(dist[e.to] <= dist[from] + cost)continue;
                dist[e.to] = dist[from] + cost;
                before[e.to] =from;
                index[e.to] = i;
                pq.push(P(dist[e.to], e.to));
            }
        }
        for(int i = 0;i < g.n;i++){
            dist[i] += potential[i];
            potential[i] = dist[i];
        }
    }

    
    Int mcf(Graph &g, Int s, Int t, Int f){
        Int res = 0;
        dist = vector<Int>(g.n);
        potential = vector<Int>(g.n);
        before = vector<Int>(g.n);
        index = vector<Int>(g.n);
        while(f){
            Dijkstra(g, s);
            Int flow = f;
            for(Int now = t;now != s;){
                Int last = before[now];
                Int ind = index[now];
                auto &e = g.edge[last][ind];
                if(e.lim == 0 || e.to != now)return -1;
                flow = min(flow, e.lim);
                now = last;
            }
            for(Int now = t;now != s;){
                Int last = before[now];
                Int ind = index[now];
                auto &e = g.edge[last][ind];
                e.lim -= flow;
                g.edge[e.to][e.rev].lim += flow;
                res += e.cost * flow;
                now = last;
            }
            f -= flow;
            if(flow==0)return -1;
        }
        return res;
    }
};

Int n, m;
Int x[88], y[88], v[88];
char dir[352];
Int a[352], b[352];
Int solve(Int F){
    Graph g(206);
    Int B = 102;
    Int Big = 1000000000000000ll;
    Int s = 101, t = 101 + B, S = 204, T= 205;
    vector<Int> xupper(101, INF), xlower(101, 0);
    vector<Int> yupper(101, INF), ylower(101, 0);
    for(int i = 0;i < m;i++){
        if(dir[i] == 'L')xupper[a[i]] = min(xupper[a[i]], b[i]);
        if(dir[i] == 'R')xlower[a[i]-1] = max(xlower[a[i]-1], F - b[i]);
        if(dir[i] == 'D')yupper[a[i]] = min(yupper[a[i]], b[i]);
        if(dir[i] == 'U')ylower[a[i]-1] = max(ylower[a[i]-1], F - b[i]);
    }
    for(int i = 0;i < n;i++) g.add_edge(x[i], y[i] + B, Big-v[i], 1);
    Int flow = F;
    for(int i = 0;i <= 100;i++){
        if(xupper[i] < xlower[i])return 0;
        if(yupper[i] < ylower[i])return 0;
        flow += xlower[i] + ylower[i];
        g.add_edge(i+1, i, 0, xupper[i]-xlower[i]);
        g.add_edge(B+i, B+i+1, 0, yupper[i]-ylower[i]);
        g.add_edge(S, i, 0, xlower[i]);
        g.add_edge(i+1, T, 0, xlower[i]);
        g.add_edge(S, B+i+1, 0, ylower[i]);
        g.add_edge(B+i, T, 0, ylower[i]);
    }
    g.add_edge(S, s, 0, F);
    g.add_edge(t, T, 0, F);
    MinCostFlow mcf;
    auto ans = mcf.mcf(g, S, T, flow);
    if(ans == -1)return 0;
    return Big*F-ans;

}


int main(){
    cin >> n;
    for(int i = 0;i < n;i++){
        cin >> x[i] >> y[i] >> v[i];
    }
    cin >> m;
    for(int i = 0;i < m;i++){
        cin >> dir[i] >> a[i] >> b[i];
    }
    Int ans = 0;
    for(int i = 1;i <= n;i++){
        auto tmp = solve(i);
        ans = max(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384