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

typedef long long int64;
const int _inf = 1e8;
namespace Flow {

const int V = 505 , E = 200010;
const int64 inf = 1e18;

int head[V] , cnt , S , T;
struct Edge {
    int to , next , flow;
    int64 cost;
}edge[E];
void init(int s , int t) {
    memset(head , 0 , sizeof(head));
    cnt = 1;
    S = s , T = t;
}
void addedge(int x , int y , int flow , int64 cost) {
    edge[++cnt] = (Edge) {y , head[x] , flow , cost}; head[x] = cnt;
    edge[++cnt] = (Edge) {x , head[y] , 0 , -cost}; head[y] = cnt;
}

int64 dis[V];
int flow[V] , pre[V];
bool vis[V];

//鏈€澶ц垂鐢ㄦ渶澶ф祦
bool spfa() {
    for(int i = 0 ; i < V ; ++i) dis[i] = -inf , flow[i] = 0;
    queue<int> q; q.push(S);
    dis[S] = 0 , flow[S] = _inf;
    do {
        int x = q.front() ; q.pop();
        vis[x] = 0;
        for(int i = head[x] ; i ; i = edge[i].next) {
            int y = edge[i].to;
            if(edge[i].flow > 0 && dis[y] < dis[x] + edge[i].cost) {
                dis[y] = dis[x] + edge[i].cost;
                pre[y] = i;
                flow[y] = min(flow[x] , edge[i].flow);
                if(!vis[y]) vis[y] = 1 , q.push(y);
            }
        }
    }while(q.size());
    return flow[T] > 0;
}
void EK(int& fl , int64& cs) {
    fl = 0 , cs = 0;
    while(spfa()) {
        cs += dis[T] * flow[T];
        fl += flow[T];
        for(int x = T ; x != S ; x = edge[pre[x]^1].to) {
            edge[pre[x]^1].flow += flow[T];
            edge[pre[x]].flow -= flow[T];
        }
    }
}

}

const int N = 85 , M = 322;

int n , m;
struct Jew {int x , y ; int64 w ;} jew[N];
struct Lim {char c ; int a , b ;} lim[M];

void readin(){
    scanf("%d" , &n);
    for(int i = 1 ; i <= n ; ++i) scanf("%d %d %lld" , &jew[i].x , &jew[i].y , &jew[i].w);
    scanf("%d" , &m);
    for(int i = 1 ; i <= m ; ++i) scanf("\n%c %d %d" , &lim[i].c , &lim[i].a , &lim[i].b);
}

int xl[N] , xr[N] , yl[N] , yr[N];

template<typename T> inline void chkmax(T &x , T y) {if(x < y) x = y;}
template<typename T> inline void chkmin(T &x , T y) {if(y < x) x = y;}

void init(int k) {
    for(int i = 1 ; i <= k ; ++i) {
        xl[i] = yl[i] = -_inf;
        xr[i] = yr[i] = _inf;
    }
    for(int i = 1 ; i <= m ; ++i) 
        switch (lim[i].c)
        {
        case 'L':
            for(int j = lim[i].b + 1 ; j <= k ; ++j)
                chkmax(xl[j] , lim[i].a + 1);
            break;
        case 'R':
            for(int j = k - lim[i].b ; j > 0; --j)
                chkmin(xr[j] , lim[i].a - 1);
            break;
        case 'D':
            for(int j = lim[i].b + 1 ; j <= k ; ++j)
                chkmax(yl[j] , lim[i].a + 1);
            break;
        case 'U':
            for(int j = k - lim[i].b ; j > 0; --j)
                chkmin(yr[j] , lim[i].a - 1);
            break;
        }
}

int64 solve(int k) {
    Flow::init(2*(n+k)+1 , 2*(n+k)+2);
    for(int i = 1 ; i <= k ; ++i) {
        Flow::addedge(Flow::S , 2*n+i , 1 , 0);
        Flow::addedge(2*n+k+i, Flow::T , 1 , 0);
    }
    for(int i = 1 ; i <= n ; ++i) 
        Flow::addedge(i , n + i , 1 , jew[i].w);
    for(int i = 1 ; i <= n ; ++i) 
        for(int j = 1 ; j <= k ; ++j) {
            if(jew[i].x >= xl[j] && jew[i].x <= xr[j])
                Flow::addedge(2*n+j , i , 1 , 0);
            if(jew[i].y >= yl[j] && jew[i].y <= yr[j])
                Flow::addedge(i+n , 2*n+k+j , 1 , 0);
        }
    int fl ; int64 cs;
    Flow::EK(fl , cs);
    if(fl != k) return 0;
    return cs;
}

int64 ans;
int main() {
    readin();
    for(int k = 1 ; k <= n ; ++k)
        init(k) , chkmax(ans , solve(k));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 768