/**
 * This line was copied from template
 * This is esol.cpp
 * 
 * @author: Nikolay Kalinin
 * @date: Sat, 16 Mar 2019 16:20:18 +0300
 */
#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

using ll = long long;
using ld = long double;
using D = double;
using uint = unsigned int;
template<typename T>
using pair2 = pair<T, T>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second

const int maxn = 505;
const ll inf = 2e18;
const int MAXC = 105;
const int infk = maxn;
const int maxk = maxn;

struct tedge
{
    int to, f, cap;
    ll cost;
    int o;
};

int x[maxn], y[maxn];
ll v[maxn];
int n, m;
int max_down[maxn], max_left[maxn], max_right[maxn], max_up[maxn];
vector<tedge> gr[maxn];
bool inq[maxn];
queue<int> q;
ll d[maxn];
int prv[maxn];
char s_tmp[5];
ll answer;
bool ok;
int maxf[maxn];

void addedge(int a, int b, int f, ll c)
{
    int ao = gr[b].size();
    int bo = gr[a].size();
    gr[a].pb({b, 0, f, c, ao});
    gr[b].pb({a, 0, 0, -c, bo});
}

void addedgeLR(int a, int b, int L, int R, ll c)
{
    if (L < 0) L = 0;
    if (R < L) ok = false, R = L;
//     cout << "addedgeLR " << a << ' ' << b << ' ' << L << ' ' << R << ' ' << c << endl;
    addedge(n + MAXC * 2, b, L, c);
    addedge(a, n + MAXC * 2 + 1, L, c);
    addedge(a, b, R - L, 2 * c);
}

bool find_path(int nn, int s, int t)
{
    for (int i = 0; i < nn; i++) d[i] = inf;
    d[s] = 0;
    while (!q.empty()) q.pop();
    q.push(s);
    for (int i = 0; i < nn; i++) inq[i] = false;
    inq[s] = true;
    maxf[s] = maxk;
    while (!q.empty())
    {
        int cur = q.front();
        q.pop();
//         cout << cur << ' ' << d[cur] << endl;
        inq[cur] = false;
        for (auto t : gr[cur]) if (t.f < t.cap && d[t.to] > d[cur] + t.cost)
        {
            d[t.to] = d[cur] + t.cost;
            prv[t.to] = t.o;
            maxf[t.to] = min(maxf[cur], t.cap - t.f);
            if (!inq[t.to])
            {
                inq[t.to] = true;
                q.push(t.to);
            }
        }
    }
//     cout << "d[t] = " << d[t] << ' ' << maxf[t] << endl;
    if (d[t] > inf / 2) return false;
    answer += maxf[t] * d[t];
    int cur = t;
    while (cur != s)
    {
        gr[cur][prv[cur]].f -= maxf[t];
        int nxt = gr[cur][prv[cur]].to;
        gr[nxt][gr[cur][prv[cur]].o].f += maxf[t];
        cur = nxt;
    }
    return true;
}

int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        scanf("%d%d%lld", &x[i], &y[i], &v[i]);
    }
    for (int i = 0; i < MAXC; i++)
    {
        max_left[i] = infk;
        max_right[i] = infk;
        max_down[i] = infk;
        max_up[i] = infk;
    }
    scanf("%d", &m);
    for (int i = 0; i < m; i++)
    {
        int a, b;
        scanf("%s%d%d", s_tmp, &a, &b);
        if (s_tmp[0] == 'L') max_left[a] = min(max_left[a], b);
        if (s_tmp[0] == 'R') max_right[a] = min(max_right[a], b);
        if (s_tmp[0] == 'U') max_up[a] = min(max_up[a], b);
        if (s_tmp[0] == 'D') max_down[a] = min(max_down[a], b);
    }
    ll bestans =0 ;
    for (int k = 1; k <= n; k++)
    {
//         cout << "try " << k << endl;
        for (int i =0; i < n + 2 * MAXC + 2; i++) gr[i].clear();
        ok = true;
        for (int i = 0; i < MAXC - 1; i++)
        {
            addedgeLR(n + i, n + i + 1, k - max_left[i], max_right[i + 1], 0);
            addedgeLR(n + MAXC + i + 1, n + MAXC + i, k - max_down[i], max_up[i + 1], 0);
        }
        for (int i = 0; i < n; i++) addedgeLR(n + x[i], n + MAXC + y[i], 0, 1, -v[i]);
        addedgeLR(n + MAXC + 0, n + 0, k, k, 0);
        if (!ok) continue;
        answer = 0;
        while (find_path(n + MAXC * 2 + 2, n + MAXC * 2 + 0, n + MAXC * 2 + 1));
        
        for (auto e : gr[n + MAXC * 2]) if (e.f != e.cap) ok = false;
        if (ok)
        {
//             cout << "ok " << -answer / 2 << endl;
            bestans = max(bestans, -answer);
        }
    }
    cout << bestans / 2 << endl;
    return 0;
}


Measured memory_bytes: 384