#include<bits/stdc++.h>

using namespace std;

int N, M, x[100], y[100], x_code[100], y_code[100], in_code[100], out_code[100], lX[100], lY[100], rX[100], rY[100], lim[400], coord[400];
long long v[100];
char type[400];
const long long INF = 1LL << 60;

class maxFlowMinCut
{
public:
    int S, D, N, t[400], c[400][400], f[400][400];
    bool inQ[400];
    long long d[400], bani[400][400];
    vector < int > v[400];

    void addEdge (int x, int y, int cap, long long ban)
    {
        c[x][y] = cap, c[y][x] = 0;
        bani[x][y] = ban, bani[y][x] = -ban;
        v[x].push_back (y);
        v[y].push_back (x);
    }

    bool bellman ()
    {
        queue < int > cc;
        for (int i=1; i<=N; i++)
            t[i] = -1, d[i] = INF, inQ[i] = 0;
        t[S] = 0, d[S] = 0, inQ[S] = 1;
        cc.push (S);
        while (!cc.empty ())
        {
            int nod = cc.front ();
            cc.pop (), inQ[nod] = 0;
            for (auto it : v[nod])
                if (c[nod][it] > f[nod][it] && d[nod] + bani[nod][it] < d[it])
                {
                    d[it] = d[nod] + bani[nod][it];
                    t[it] = nod;
                    if (!inQ[it])
                        inQ[it] = 1,
                        cc.push (it);
                }
        }
        return (d[D] < INF);
    }

    pair < int, long long > minCostMaxFlow ()
    {
        int cap = 0;
        long long ban = 0;
        while (bellman ())
        {
            int minC = 1e9;
            for (int i=D; i != S; i = t[i])
                minC = min (minC, c[t[i]][i] - f[t[i]][i]);
            for (int i=D; i != S; i = t[i])
                f[t[i]][i] += minC,
                f[i][t[i]] -= minC;
            cap += minC, ban += 1LL * minC * d[D];
        }
        return {cap, ban};
    }

    void clear ()
    {
        for (int i=1; i<=N; i++)
        {
            for (auto j : v[i])
                c[i][j] = c[j][i] = 0,
                f[i][j] = f[j][i] = 0,
                bani[i][j] = bani[j][i] = 0LL;
            v[i].clear ();
        }
        S = D = N = 0;
    }
}net;

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d", &N);
for (int i=1; i<=N; i++)
    scanf ("%d %d %lld", &x[i], &y[i], &v[i]);
scanf ("%d\n", &M);
for (int i=1; i<=M; i++)
    scanf ("%c %d %d\n", &type[i], &coord[i], &lim[i]);
long long best = 0;
for (int K=1; K<=N; K++)
{
    net.clear (), net.S = 1, net.D = net.N = 2;
    for (int i=1; i<=K; i++)
        x_code[i] = ++net.N,
        net.addEdge (net.S, x_code[i], 1, 0);
    for (int i=1; i<=N; i++)
        in_code[i] = ++net.N,
        out_code[i] = ++net.N,
        net.addEdge (in_code[i], out_code[i], 1, -v[i]);
    for (int i=1; i<=K; i++)
        y_code[i] = ++net.N,
        net.addEdge (y_code[i], net.D, 1, 0);
    for (int i=1; i<=K; i++)
        lX[i] = lY[i] = 0,
        rX[i] = rY[i] = 200;
    for (int i=1; i<=M; i++)
    {
        if (type[i] == 'L' && lim[i] < K) lX[lim[i] + 1] = max (lX[lim[i] + 1], coord[i] + 1);
        if (type[i] == 'R' && lim[i] < K) rX[K - lim[i]] = min (rX[K - lim[i]], coord[i] - 1);
        if (type[i] == 'D' && lim[i] < K) lY[lim[i] + 1] = max (lY[lim[i] + 1], coord[i] + 1);
        if (type[i] == 'U' && lim[i] < K) rY[K - lim[i]] = min (rY[K - lim[i]], coord[i] - 1);
    }
    for (int i=2; i<=K; i++)
        lX[i] = max (lX[i], lX[i - 1]),
        lY[i] = max (lY[i], lY[i - 1]);
    for (int i=K - 1; i>=1; i--)
        rX[i] = min (rX[i], rX[i + 1]),
        rY[i] = min (rY[i], rY[i + 1]);
    for (int i=1; i<=K; i++)
        for (int j=1; j<=N; j++)
        {
            if (lX[i] <= x[j] && x[j] <= rX[i])
                net.addEdge (x_code[i], in_code[j], 1, 0);
            if (lY[i] <= y[j] && y[j] <= rY[i])
                net.addEdge (out_code[j], y_code[i], 1, 0);
        }
/*    for (int i=1; i<=N; i++)
        if (i == 1 || (5 <= i && i <= 7))
            printf ("%d %d\n", x[i], y[i]);
    for (int i=1; i<=K; i++)
        printf ("[%d %d] [%d %d]\n", lX[i], rX[i], lY[i], rY[i]);*/
    auto ans = net.minCostMaxFlow ();
    //printf ("%d -> %lld\n", ans.first, -ans.second);
    if (ans.first == K)
    {
        if (-ans.second > best)
            best = -ans.second;
    }
}
printf ("%lld\n", best);
return 0;
}


Measured memory_bytes: 2432