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

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

#define all(x) (x).begin(), (x).end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

template<typename F, typename C> struct min_cost_flow {
    static constexpr int bits = 63 - __builtin_clzll(numeric_limits<F>::max());

    int V;
    vvi adj;
    vi dest;
    vector<F> cap;
    vector<C> cost;

    min_cost_flow(int V = 0) : V(V) {
        adj.resize(V);
    }

    void __arc(int u, int v, F f, C c) {
        adj[u].push_back(dest.size());
        dest.push_back(v);
        cap.push_back(f);
        cost.push_back(c);
    }

    // Inserts a directed edge u --> v with capacity f and cost c.
    void arc(int u, int v, F f, C c) {
        __arc(u, v, f, c);
        __arc(v, u, F(0), -c);
    }

    bool dijkstra(auto& imb, auto& flow, auto& pot, F delta) {
        priority_queue<tuple<C, int, int>> q;
        vi ent(V, -2);
        vector<C> dist(V, numeric_limits<C>::max());
        for (int v = 0; v < V; v++) if (imb[v] >= delta)
            q.push(make_tuple(0., v, -1));

        while (!q.empty()) {
            C d; int v, f; tie(d, v, f) = q.top(); q.pop();
            if (ent[v] != -2) continue;
            dist[v] = -d; ent[v] = f;
            for (int e : adj[v]) if (cap[e] - flow[e] >= delta)
                q.push(make_tuple(d - (cost[e] + pot[v] - pot[dest[e]]), dest[e], e ));
        }

        for (int v = 0; v < V; v++) if (ent[v] != -2 && imb[v] <= -delta) {
            for (int u = 0; u < V; u++) pot[u] += dist[u];
            for (int e = ent[v]; ~e; e = ent[dest[e^1]]) {
                flow[e] += delta;
                flow[e^1] -= delta;
                imb[dest[e]] += delta;
                imb[dest[e^1]] -= delta;
            }
            return true;
        }
        return false;
    }

    // O(E^2 * log V * bits)
    pair<bool, C> solve(vector<F>& imb) {
        vector<F> flow(cap.size());
        vector<C> pot(V);
        for (F delta = 1ll << bits; delta; delta >>= 1) {
            for (int e = 0; e < dest.size(); e++) {
                int u = dest[e^1], v = dest[e];
                F res = cap[e] - flow[e];
                if (res >= delta && cost[e] + pot[u] - pot[v] < 0) {
                    flow[e^1] -= res;
                    flow[e] += res;
                    imb[u] -= res;
                    imb[v] += res;
                }
            }
            while (dijkstra(imb, flow, pot, delta));
        }

        C ans = 0;
        for (int e = 0; e < dest.size(); e++) if (flow[e] > 0)  {
            ans += flow[e] * cost[e];
        }
        return { imb == vector<F>(V, 0), ans };
    }
};

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    int N, M;
    cin >> N;

    vi x(N), y(N); vll val(N);
    for (int i = 0; i < N; i++) {
        cin >> x[i] >> y[i] >> val[i];
    }

    cin >> M;
    string dir(M, '.'); vi loc(M), qua(M);
    for (int i = 0; i < M; i++) {
        cin >> dir[i] >> loc[i] >> qua[i];
    }

    auto pmin = [](vi& v, int inx, int val) {
        if (inx >= 0 && inx < v.size()) v[inx] = min(v[inx], val);
    };
    auto pmax = [](vi& v, int inx, int val) {
        if (inx >= 0 && inx < v.size()) v[inx] = max(v[inx], val);
    };
    auto best = [&](int K) {
        vi xlo(K, 1), xhi(K, 100), ylo(K, 1), yhi(K, 100);
        for (int i = 0; i < M; i++) {
            if (dir[i] == 'L') pmax(xlo, qua[i], loc[i] + 1);
            if (dir[i] == 'R') pmin(xhi, K - 1 - qua[i], loc[i] - 1);
            if (dir[i] == 'D') pmax(ylo, qua[i], loc[i] + 1);
            if (dir[i] == 'U') pmin(yhi, K - 1 - qua[i], loc[i] - 1);
        }
        for (int i = 1; i < K; i++) {
            xlo[i] = max(xlo[i], xlo[i-1]);
            ylo[i] = max(ylo[i], ylo[i-1]);
        }
        for (int i = K - 2; i >= 0; i--) {
            xhi[i] = min(xhi[i], xhi[i+1]);
            yhi[i] = min(yhi[i], yhi[i+1]);
        }

        const int V = 1 + K + 2 * N + K + 1;
        const int SRC = 0, XL = 1, JL = 1 + K, YL = 1 + K + 2 * N, SNK = V - 1;

        min_cost_flow<int, ll> g(V);
        for (int i = 0; i < K; i++) {
            g.arc(SRC, XL + i, 1, 0);
            for (int j = 0; j < N; j++) {
                if (xlo[i] <= x[j] && x[j] <= xhi[i])
                    g.arc(XL + i, JL + j, 1, 0);
            }
            g.arc(YL + i, SNK, 1, 0);
            for (int j = 0; j < N; j++) {
                if (ylo[i] <= y[j] && y[j] <= yhi[i])
                    g.arc(JL + N + j, YL + i, 1, 0);
            }
        }
        const ll MAXV = 1e15;
        for (int j = 0; j < N; j++) {
            g.arc(JL + j, JL + N + j, 1, MAXV - val[j]);
        }

        vi imb(V);
        imb[SRC] = K;
        imb[SNK] = -K;
        auto res = g.solve(imb);
        return res.first ? MAXV * K - res.second : 0ll;
    };

    ll ans = 0;
    for (int k = 1; k <= N; k++)
        ans = max(ans, best(k));
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 1100