#include<iostream>
#include<vector>
#include<queue>
using namespace std;
int n, m, i, dest, srs;
long long sol;
struct str1{
    int x, y;
    long long c;
};
str1 wn[85];
struct str2{
    char tip;
    int p, nr;
};
str2 wm[330];
int c[400][400], f[400][400], xst[85], xdr[85], yst[85], ydr[85], viz[400], t[400];
long long z[400][400], d[400];
vector<int> v[400];
queue<int> cd;
void muchie(int x, int y, int cc, long long cost){
    v[x].push_back(y);
    v[y].push_back(x);
    c[x][y] = cc;
    z[x][y] = cost;
    z[y][x] = -cost;
}
void bf(){
    int i, nod, vecin;
    for(i = 0; i <= dest; i++){
        d[i] = 1000000000000000000LL;
        t[i] = -1;
        viz[i] = 0;
    }
    d[srs] = 0;
    cd.push(srs);
    while(!cd.empty()){
        nod = cd.front();
        cd.pop();
        viz[nod] = 0;
        for(i = 0; i < v[nod].size(); i++){
            vecin = v[nod][i];
            if(d[vecin] > d[nod] + z[nod][vecin] && c[nod][vecin] > f[nod][vecin]){
                d[vecin] = d[nod] + z[nod][vecin];
                t[vecin] = nod;
                if(viz[vecin] == 0){
                    viz[vecin] = 1;
                    cd.push(vecin);
                }
            }
        }
    }
}
long long solve(int k){
    int i, j, u, sum, minim;
    long long sol = 0;
    for(i = 1; i <= k; i++){
        xst[i] = yst[i] = 0;
        xdr[i] = ydr[i] = 101;
    }
    for(i = 1; i <= m; i++){
        if(wm[i].tip == 'L'){
            if(wm[i].nr + 1 <= k){
                xst[ wm[i].nr + 1] = max(xst[ wm[i].nr + 1], wm[i].p + 1);
            }
        }
        if(wm[i].tip == 'R'){
            if(k - wm[i].nr > 0){
                xdr[ k - wm[i].nr ] = min(xdr[ k - wm[i].nr ], wm[i].p - 1);
            }
        }
        if(wm[i].tip == 'D'){
            if(wm[i].nr + 1 <= k){
                yst[ wm[i].nr + 1] = max(yst[ wm[i].nr + 1], wm[i].p + 1);
            }
        }
        if(wm[i].tip == 'U'){
            if(k - wm[i].nr > 0){
                ydr[ k - wm[i].nr ] = min(ydr[ k - wm[i].nr ], wm[i].p - 1);
            }
        }
    }
    for(i = 2; i <= k; i++){
        xst[i] = max(xst[i], xst[i - 1]);
        yst[i] = max(yst[i], yst[i - 1]);
    }
    for(i = k - 1; i >= 1; i--){
        xdr[i] = min(xdr[i], xdr[i + 1]);
        ydr[i] = min(ydr[i], ydr[i + 1]);
    }
    dest = k * 2 + 200 + 1;
    srs = 0;
    for(i = srs; i <= dest; i++){
        v[i].clear();
        for(j = srs; j <= dest; j++){
            f[i][j] = c[i][j] = z[i][j] = 0;
        }
    }
    for(i = 1; i <= k; i++){
        muchie(0, i, 1, 0);
        muchie(k + 200 + i, dest, 1, 0);
    }
    for(i = 1; i <= 100; i++){
        for(j = 1; j <= k; j++){
            if(i >= xst[j] && i <= xdr[j]){
                muchie(j, k + i, 1, 0);
            }
            if(i >= yst[j] && i <= ydr[j]){
                muchie(k + 100 + i, j + k + 200, 1, 0);
            }
        }
    }
    for(i = 1; i <= n; i++){
        muchie(k + wn[i].x, k + 100 + wn[i].y, 1, 1000000000000000LL - wn[i].c);
    }
    sum = 0;
    for(i = 1; i <= k; i++){
        bf();
        if(t[dest] == -1){
            break;
        }
        minim = 1000;
        sol += 1000000000000000LL - d[dest];
        for(u = dest; t[u] != -1; u = t[u]){
            minim = min(minim, c[ t[u] ][u] - f[ t[u] ][u]);
        }
        sum += minim;
        for(u = dest; t[u] != -1; u = t[u]){
            f[ t[u] ][u] += minim;
            f[u][ t[u] ] -= minim;
        }
    }
    if(sum == k){
        return sol;
    }
    else{
        return -100000000000000LL;
    }
}
int main(){
    cin>> n;
    for(i = 1; i <= n; i++){
        cin>> wn[i].x >> wn[i].y >> wn[i].c;
    }
    cin>> m;
    for(i = 1; i <= m; i++){
        cin>> wm[i].tip >> wm[i].p >> wm[i].nr;
    }
    for(i = 1; i <= n; i++){
        sol = max(sol, solve(i));
    }
    cout<< sol;
}


Measured memory_bytes: 2688