#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');
}
namespace MIN_COST_MAX_FLOW {
typedef LL Flow;
typedef LL Cost;
const Flow FLOW_INF = 1LL<<60;
const Cost COST_INF = 1LL<<60;

const int SIZE = 65;
vector<pair<Cost, int> > B[SIZE];
Cost last;
int sz;

int bsr(Cost c) {
    if (c == 0) return 0;
    return __lg(c)+1;
}

void init() {
    last = sz = 0;
    REP (i, SIZE) B[i].clear();
}

void push(Cost cst, int v) {
    assert(cst >= last);
    sz++;
    B[bsr(cst^last)].emplace_back(cst, v);
}

pair<Cost, int> pop_min() {
    assert(sz);
    if (B[0].empty()) {
	int k = 1;
	while (k < SIZE && B[k].empty()) k++;
	assert(k < SIZE);
	last = B[k][0].first;
	EACH (e, B[k]) amin(last, e->first);
	EACH (e, B[k]) B[bsr(e->first^last)].push_back(*e);
	B[k].clear();
    }
    assert(B[0].size());
    pair<Cost, int> ret = B[0].back();
    B[0].pop_back();
    sz--;
    return ret;
}

struct MinCostMaxFlow {
    struct Edge {
	int dst;
	Cost cst;
	Flow cap;
	int rev;
    };
    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){ v, x, f, (int)G[v].size() });
	G[v].push_back((Edge){ 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) {
	    init(); push(0, s);
	    fill(len.begin(), len.end(), COST_INF);
	    fill(prev.begin(), prev.end(), -1);
	    len[s] = 0;
	    while (sz) {
		pair<Cost, int> p = pop_min();
		Cost cst = p.first;
		int v = p.second;
		if (cst > len[v]) continue;
		for (int i=0; i<(int)G[v].size(); i++) {
		    const Edge &f = G[v][i];
		    Cost tmp = len[v] + f.cst + h[v] - h[f.dst];
		    if (f.cap > 0 && len[f.dst] > tmp) {
			len[f.dst] = tmp;
			push(tmp, f.dst);
			prev[f.dst] = v; 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;
    }
};
}; // namespace

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;
    MIN_COST_MAX_FLOW::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: 1248