#include <bits/stdc++.h>

using namespace std;

namespace mcmf {

const long long inf = 1000111222000111222LL;

struct edge {
    int to, flow, capacity;
    long long cost;

    edge() {
    }

    edge(int to, int flow, int capacity, long long cost): to(to), flow(flow), capacity(capacity), cost(cost) {
    }

};

const int max_v = 404;

vector<edge> edges;
vector<int> g[max_v];

void clr() {
    edges.clear();
    for (int i = 0; i < max_v; ++i) {
        g[i].clear();
    }
}

void add_edge(int u, int v, int capacity, long long cost) {
    g[u].push_back(edges.size());
    edges.push_back(edge(v, 0, capacity, cost));
    g[v].push_back(edges.size());
    edges.push_back(edge(u, 0, 0, -cost));
}

int parent[max_v], p_id[max_v];
long long phi[max_v], dist[max_v];

long long dijkstra(int s, int t) {
    for (int i = 0; i <= t; ++i) {
        dist[i] = inf;
    }
    priority_queue<pair<long long, int>> q;
    dist[s] = 0;
    q.push({0, s});
    while (!q.empty()) {
        pair<long long, int> p = q.top();
        q.pop();
        long long d = -p.first, v = p.second;
        if (d != dist[v]) {
            continue;
        }
        for (int id : g[v]) {
            if (edges[id].flow == edges[id].capacity) {
                continue;
            }
            int to = edges[id].to;
            // cout << v << " " << dist[v] << " -> " << to << " " << edges[id].cost << endl;
            if (dist[v] + edges[id].cost + phi[v] - phi[to] < dist[to]) {
                dist[to] = dist[v] + edges[id].cost + phi[v] - phi[to];
                parent[to] = v;
                p_id[to] = id;
                q.push({-dist[to], to});
            }
        }
    }
    if (dist[t] == inf) {
        return inf;
    }
    for (int i = 0; i <= t; ++i) {
        phi[i] = min(inf, dist[i] + phi[i]);
    }
    int v = t;
    while (v != s) {
        ++edges[p_id[v]].flow;
        --edges[p_id[v] ^ 1].flow;
        v = parent[v];
    }
    return phi[t];
}

long long min_cost_max_flow(int s, int t, int k) {
    for (int i = 0; i <= t; ++i) {
        phi[i] = 0;
    }
    long long res = 0;
    int it = 0;
    while (true) {
        long long x = dijkstra(s, t);
        if (x == inf) {
            break;
        }
        ++it;
        res += x;
    }
    if (it != k) {
        return 0;
    }
    return res;
}

}

const int max_n = 105;
const int max_c = 333;
const long long inf = 1000111222000111LL;

int lx[max_n], rx[max_n], ly[max_n], ry[max_n];

struct constraint {
    char tp;
    int x, cnt;

    void read() {
        scanf("\n%c%d%d", &tp, &x, &cnt);
        --x;
    }

    void add(int k) {
        if (tp == 'L') {
            for (int i = cnt; i < k; ++i) {
                lx[i] = max(lx[i], x + 1);
            }
        } else if (tp == 'D') {
            for (int i = cnt; i < k; ++i) {
                ly[i] = max(ly[i], x + 1);
            }
        } else if (tp == 'R') {
            for (int i = 0; i < k - cnt; ++i) {
                rx[i] = min(rx[i], x - 1);
            }
        } else {
            for (int i = 0; i < k - cnt; ++i) {
                ry[i] = min(ry[i], x - 1);
            }
        }
    }
};

int n, m, x[max_n], y[max_n];
long long v[max_n];
constraint c[max_c];

long long solve(int k) {
    for (int i = 0; i < k; ++i) {
        lx[i] = ly[i] = 0;
        rx[i] = ry[i] = 99;
    }
    for (int i = 0; i < m; ++i) {
        c[i].add(k);
    }
    for (int i = 0; i < k; ++i) {
        if (lx[i] > rx[i] || ly[i] > ry[i]) {
            return 0;
        }
    }
    if (0) {
        cout << k << ": " << endl;
        for (int i = 0; i < k; ++i) {
            cout << lx[i] << " " << rx[i] << ", " << ly[i] << " " << ry[i] << endl;
        }
        cout << endl;
    }
    mcmf::clr();
    const int max_x = 100;
    int s = 2 * k + 2 * max_x;
    int t = s + 1;
    for (int i = 0; i < k; ++i) {
        mcmf::add_edge(s, i, 1, 0);
        for (int x = lx[i]; x <= rx[i]; ++x) {
            mcmf::add_edge(i, k + x, 1, 0);
        }
        mcmf::add_edge(k + 2 * max_x + i, t, 1, 0);
        for (int y = ly[i]; y <= ry[i]; ++y) {
            mcmf::add_edge(k + max_x + y, k + 2 * max_x + i, 1, 0);
        }
    }
    for (int i = 0; i < n; ++i) {
        mcmf::add_edge(k + x[i], k + max_x + y[i], 1, -v[i] + inf);
    }
    long long res = -mcmf::min_cost_max_flow(s, t, k);
    if (res == 0) {
        return 0;
    }
    return res + k * inf;
}

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%d%d%lld", &x[i], &y[i], &v[i]);
        --x[i];
        --y[i];
    }
    scanf("%d", &m);
    for (int i = 0; i < m; ++i) {
        c[i].read();
    }
    long long ans = 0;
    for (int i = 1; i <= n; ++i) {
        long long res = solve(i);
        if (res == 0) {
            break;
        }
        // cout << i << ": " << solve(i) << endl;
        ans = max(ans, solve(i));
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 1184