#include <bits/stdc++.h>
#define mset(a, b) memset(a, b, sizeof(a))
#define mcpy(a, b) memcpy(a, b, sizeof(a))
using namespace std;
typedef long long LL;
const int N = 405;
const int M = 100005;
const LL INF = 0x3f3f3f3f3f3f3f3f;

template <typename T> inline void read(T &AKNOI) {
	T x = 0, flag = 1;
	char ch = getchar();
	while (!isdigit(ch)) {
		if (ch == '-') flag = -1;
		ch = getchar();
	}
	while (isdigit(ch)) {
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	AKNOI = flag * x;
}

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

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

int tot, S, T, inq[N], pre[N];
LL dis[N];
queue<int> q;

struct Edge {
	int v, w, nxt;
	LL c;
} e[M << 1];
int first[N], eCnt;

inline void AddEdge(int u, int v, int w, LL c) {
	e[++eCnt].v = v;
	e[eCnt].w = w;
	e[eCnt].c = c;
	e[eCnt].nxt = first[u];
	first[u] = eCnt;
}

inline void Add(int u, int v, int w, LL c) {
	AddEdge(u, v, w, c);
	AddEdge(v, u, 0, -c);
}

bool SPFA() {
	for (int i = 1; i <= tot; ++i) {
		dis[i] = -INF;
	}
	dis[S] = 0;
	q.push(S);
	while (!q.empty()) {
		int u = q.front();
		q.pop(); inq[u] = 0;
		for (int i = first[u]; i; i = e[i].nxt) {
			int v = e[i].v;
			if (e[i].w && dis[v] < dis[u] + e[i].c) {
				dis[v] = dis[u] + e[i].c;
				pre[v] = i;
				if (!inq[v]) {
					q.push(v);
					inq[v] = 1;
				}
			}
		}
	}
	return (dis[T] > -INF);
}

LL Update() {
	int flow = 100;
	for (int i = pre[T]; i; i = pre[e[i ^ 1].v]) {
		cmin(flow, e[i].w);
	}
	for (int i = pre[T]; i; i = pre[e[i ^ 1].v]) {
		e[i].w -= flow;
		e[i ^ 1].w += flow;
	}
	return dis[T] * flow;
}

LL Costflow() {
	LL mxcost = 0;
	while (SPFA()) {
		mxcost += Update();
	}
	return mxcost;
}

char qt[N];
int n, m, X[N], Y[N], qa[N], qb[N];
LL V[N];
int lx[N], rx[N], ly[N], ry[N];

LL Work(int x) {
	mset(first, 0);
	eCnt = 1;
	S = 201, T = tot = 202;
	for (int i = 1; i <= x; ++i) {
		lx[i] = ly[i] = 1;
		rx[i] = ry[i] = 100;
	}
	
	for (int i = 1; i <= m; ++i) {
		if (qb[i] > x) continue;
		if (qt[i] == 'L') {
			cmax(lx[qb[i] + 1], qa[i] + 1);
		} else if (qt[i] == 'R') {
			cmin(rx[x - qb[i]], qa[i] - 1);
		} else if (qt[i] == 'D') {
			cmax(ly[qb[i] + 1], qa[i] + 1);
		} else if (qt[i] == 'U') {
			cmin(ry[x - qb[i]], qa[i] - 1);
		}
	}
	for (int i = 2; i <= x; ++i) {
		cmax(lx[i], lx[i - 1]);
		cmax(ly[i], ly[i - 1]);
	}
	for (int i = x - 1; i >= 1; --i) {
		cmin(rx[i], rx[i + 1]);
		cmin(ry[i], ry[i + 1]);
	}
	
	for (int i = 1; i <= n; ++i) {
		Add(X[i], 100 + Y[i], 1, V[i]);
	}
	for (int i = 1; i <= x; ++i) {
		if (lx[i] > rx[i] || ly[i] > ry[i]) return -INF;
		Add(S, ++tot, 1, 0);
		for (int j = lx[i]; j <= rx[i]; ++j) {
			Add(tot, j, 1, 0);
		}
		Add(++tot, T, 1, 0);
		for (int j = ly[i]; j <= ry[i]; ++j) {
			Add(100 + j, tot, 1, 0);
		}
	}
	return Costflow();
}

void init() {
	read(n);
	for (int i = 1; i <= n; ++i) {
		read(X[i]); read(Y[i]); read(V[i]);
	}
	read(m);
	for (int i = 1; i <= m; ++i) {
		qt[i] = getchar();
		read(qa[i]); read(qb[i]);
	}
}

void solve() {
	LL ans = 0;
	for (int i = 1; i <= n; ++i) {
		cmax(ans, Work(i));
	}
	printf("%lld\n", ans);
}

int main() {
	init();
	solve();
	return 0;
}


Measured memory_bytes: 896