#include<queue>
#include<stack>
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}
struct MinCostMaxFlow {
    typedef LL Flow;
    typedef LL Cost;
    static const Flow FLOW_INF = 1LL<<60;
    static const Cost COST_INF = 1LL<<60;
    struct Edge {
	int src, dst;
	Cost cst;
	Flow cap;
	int rev;
	bool operator<(const Edge&y) const {
	    return cst > y.cst;
	}
    };
    typedef vector<vector<Edge> > Graph;
    Graph G;
    MinCostMaxFlow(int N) : G(N) {}

    void add_edge(int u, int v, Cost x, Flow f) {
	if (u == v) return;
	G[u].push_back((Edge){ u, v, x, f, (int)G[v].size() });
	G[v].push_back((Edge){ v, u, -x, 0, (int)G[u].size()-1 });
    }

    Flow flow;
    Cost cost;
    Flow solve(int s, int t, Flow limit = FLOW_INF) {
	flow = 0;
	cost = 0;
	vector<Cost>len(G.size()), h(G.size(), 0);
	vector<int> prev(G.size()), prev_num(G.size());
	while (limit > 0) {
	    priority_queue<Edge> Q;
	    Q.push((Edge){-2, s, 0, 0, 0});
	    fill(len.begin(), len.end(), COST_INF);
	    fill(prev.begin(), prev.end(), -1);
	    len[s] = 0;
	    while (!Q.empty()) {
		Edge e = Q.top(); Q.pop();
		if (e.cst > len[e.dst]) continue;
		for (int i=0; i<(int)G[e.dst].size(); i++) {
		    const Edge &f = G[e.dst][i];
		    if (f.cap > 0 && len[f.dst] > len[f.src] + f.cst + h[f.src] - h[f.dst]) {
			len[f.dst] = len[f.src] + f.cst + h[f.src] - h[f.dst];
			Q.push((Edge){ f.src, f.dst, len[f.dst], 0, 0 });
			prev[f.dst] = f.src; prev_num[f.dst] = i;
		    }
		}
	    }
	    if (prev[t] == -1) return flow;
	    for (int i=0; i<(int)G.size(); i++) h[i] += len[i];
	    
	    Flow f = limit;
	    for (int v=t; v!=s; v=prev[v])
		f = min(f, G[prev[v]][prev_num[v]].cap);
	    for (int v=t; v!=s; v=prev[v]) {
		Edge &e = G[prev[v]][prev_num[v]];
		e.cap -= f;
		G[e.dst][e.rev].cap += f;
	    }
	    limit -= f;
	    flow += f;
	    cost += f * h[t];
	}
	return flow;
    }
};
const MinCostMaxFlow::Flow MinCostMaxFlow::FLOW_INF;
const MinCostMaxFlow::Cost MinCostMaxFlow::COST_INF;

int N;
int X[88], Y[88];
LL V[88];
int M;
char T[333];
int A[333], B[333];

int Llo[88], Lhi[88], Dlo[88], Dhi[88];
const LL BASE = 1LL<<50;
LL calc(int K) {
    memset(Lhi, 0x3f, sizeof Lhi);
    memset(Llo, 0xc0, sizeof Llo);
    memset(Dhi, 0x3f, sizeof Dhi);
    memset(Dlo, 0xc0, sizeof Dlo);
    REP (j, M) {
	int a = A[j], b = B[j];
	if (b < K) {
	    if (T[j] == 'L') amax(Llo[b], a);
	    if (T[j] == 'R') amin(Lhi[K-b-1], a);
	    if (T[j] == 'D') amax(Dlo[b], a);
	    if (T[j] == 'U') amin(Dhi[K-b-1], a);
	}
    }
    REP (i, K-1) {
	amax(Llo[i+1], Llo[i]);
	amax(Dlo[i+1], Dlo[i]);
    }
    for (int i=K-2; i>=0; i--) {
	amin(Lhi[i], Lhi[i+1]);
	amin(Dhi[i], Dhi[i+1]);
    }
//    rprintf("%d", Llo, Llo+K);
//    rprintf("%d", Lhi, Lhi+K);
//    rprintf("%d", Dlo, Dlo+K);
//    rprintf("%d", Dhi, Dhi+K);
//
    const int SRC = K*2+N*2, SNK = SRC+1;
    MinCostMaxFlow G(SNK+1);
    REP (i, N) {
	int left = i+K*2, right = left + N;
	G.add_edge(left, right, BASE - V[i], 1);
	REP (a, K) {
	    if (Llo[a] < X[i] && X[i] < Lhi[a]) {
		G.add_edge(a, left, 0, 1);
	    }
	    if (Dlo[a] < Y[i] && Y[i] < Dhi[a]) {
		G.add_edge(right, a+K, 0, 1);
	    }
	}
    }
    REP (a, K) {
	G.add_edge(SRC, a, 0, 1);
	G.add_edge(a+K, SNK, 0, 1);
    }
    G.solve(SRC, SNK);
    if (G.flow == K) {
	return K * BASE - G.cost;
    } else {
	return -1;
    }

}

void MAIN() {
    scanf("%d", &N);
    REP (i, N) scanf("%d%d%lld", X+i, Y+i, V+i);
    scanf("%d", &M);
    REP (i, M) scanf("%s%d%d", T+i, A+i, B+i);

    
    LL ans = 0;
    for (int k=1; k<=N; k++) {
	LL tmp = calc(k);
	if (tmp == -1) break;
	amax(ans, tmp);
    }
    
    printf("%lld\n", ans);

}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 1232