#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct edge {
    int v, nxt, f;
    ll c;
} e[2 * 80 * 80 * 8 + 10];
int head[410], tot, cur[410];
inline void init() {
    tot = 1;
    memset(head, 0, sizeof head);
}
inline void addedge(int u, int v, int f, ll c) {
    e[++tot] = edge{v, head[u], f, c};
    head[u] = tot;
    e[++tot] = edge{u, head[v], 0, -c};
    head[v] = tot;
}
int n, m, x[100], y[100];
ll v[100];
struct node {
    char type;
    int key, val;
} a[325];
ll dis[410];
int inq[410];
int s, t;
inline bool spfa() {
    memset(dis, ~0x3f, sizeof dis);
    queue <int> q;
    q.push(s);
    dis[s] = 0;
    inq[s] = 1;
    while (!q.empty()) {
        int now = q.front();
        q.pop();
        for (int i = head[now]; i; i = e[i].nxt) {
            if (e[i].f && dis[now] + e[i].c > dis[e[i].v]) {
                dis[e[i].v] = dis[now] + e[i].c;
                if (!inq[e[i].v]) inq[e[i].v] = 1, q.push(e[i].v);
            }
        }
        inq[now] = 0;
    }
    return memcpy(cur, head, sizeof cur), dis[t] >= -1e18;
}
int ansf, insta[410];
ll ansc;
inline int dfs(int now, int limit) {
    if (now == t) return limit;
    insta[now] = 1;
    int ans = 0;
    for (int &i = cur[now]; i; i = e[i].nxt) {
        if (e[i].f == 0 || dis[now] + e[i].c != dis[e[i].v] || insta[e[i].v]) continue;
        int tmp = dfs(e[i].v, min(limit, e[i].f));
        ans += tmp, limit -= tmp;
        ansc += tmp * e[i].c;
        e[i].f -= tmp;
        e[i ^ 1].f += tmp;
        if (limit == 0) return insta[now] = 0, ans;
    }
    return insta[now] = 0, ans;
}
inline void work() {
    ansf = ansc = 0;
    while (spfa()) ansf += dfs(s, 1e9);
}
int l[100], r[100];
int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d%d%lld", x + i, y + i, v + i);
    scanf("%d", &m);
    for (int i = 1; i <= m; i++) scanf("%s%d%d", &a[i].type, &a[i].key, &a[i].val);
    ll ans = 0;
    for (int k = 1; k <= n; k++) {
        init();
        for (int i = 1; i <= n; i++) l[i] = 0, r[i] = 100;
        for (int i = 1; i <= m; i++) {
            switch (a[i].type) {
                case 'L': {
                    for (int j = a[i].val + 1; j <= k; j++) l[j] = max(l[j], a[i].key + 1);
                    break;
                }
                case 'R': {
                    for (int j = 1; j <= k - a[i].val; j++) r[j] = min(r[j], a[i].key - 1);
                    break;
                }
            }
        }
        for (int i = 1; i <= k; i++)
            for (int j = 1; j <= n; j++)
                if (x[j] >= l[i] && x[j] <= r[i]) addedge(i, j + k, 1, 0);
        for (int i = 1; i <= n; i++) l[i] = 0, r[i] = 100;
        for (int i = 1; i <= m; i++) {
            switch (a[i].type) {
                case 'D': {
                    for (int j = a[i].val + 1; j <= k; j++) l[j] = max(l[j], a[i].key + 1);
                    break;
                }
                case 'U': {
                    for (int j = 1; j <= k - a[i].val; j++) r[j] = min(r[j], a[i].key - 1);
                    break;
                }
            }
        }
        for (int i = 1; i <= k; i++)
            for (int j = 1; j <= n; j++)
                if (y[j] >= l[i] && y[j] <= r[i]) addedge(j + k + n, i + k + n + n, 1, 0);
        s = 0, t = k + k + n + n + 1;
        for (int i = 1; i <= k; i++) addedge(s, i, 1, 0), addedge(i + n + n + k, t, 1, 0);
        for(int i = 1; i <= n; i++) addedge(i + k, i + k + n, 1, v[i]);
        work();
        if (ansf != k) continue;
        ans = max(ans, ansc);
    }
    return cout << ans << endl, 0;
}

Measured memory_bytes: 640