#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define FASTIO
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;


/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

const int MAXN = 210;

struct edge {
	int a, b;
	int f, c;
	ll w;
};


int s, t;
vector<edge> ed;

vector<int> eds[MAXN];

void add_edge(int a, int b, int c, ll w) {
	edge x;
	x.a = a, x.b = b, x.c = c, x.f = 0, x.w = w;
	eds[a].push_back(ed.size());
	ed.push_back(x);
	swap(x.a, x.b), x.c = 0, x.w = -w;
	eds[b].push_back(ed.size());
	ed.push_back(x);
}


const ll INF = 1e18;
int en[210];
ll dd[210];
int go[210];
queue<int> qu;

void clear() {
	ed.clear();
	for (int i = 0; i <= t; ++i)
		eds[i].clear();
}

pair<int, ll> flow() {
	int cur = 0;
	ll cost = 0;
	while (true) {
		fill(en, en + t + 1, 0);
		fill(dd, dd + t + 1, INF);
		fill(go, go + t + 1, -1);
		dd[s] = 0;
		qu.push(s);
		en[s] = 1;
		while (!qu.empty()) {
			int x = qu.front();
			qu.pop();
			en[x] = 0;
			for (int e: eds[x]) {
				if (ed[e].c == ed[e].f)
					continue;
				int u = ed[e].b;
				if (dd[u] > dd[x] + ed[e].w) {
					dd[u] = dd[x] + ed[e].w;
					go[u] = e;
					if (!en[u])
						en[u] = 1, qu.push(u);
				}
			}
		}
		if (dd[t] == INF)
			break;
		int mn = 200;
		int now = t;
		while (now != s) {
			int e = go[now];
			mn = min(mn, ed[e].c - ed[e].f);
			now = ed[e].a;
		}
		now = t;
		cur += mn;
		cost += mn * dd[t];
		while (now != s) {
			int e = go[now];
			ed[e].f += mn;
			ed[e ^ 1].f -= mn;
			now = ed[e].a;
		}
	}
	return {cur, cost};
}


vector<tuple<int, int, ll>> ad;

int n;
int m;
int lb[210], rb[210];

int main() {
#ifdef FASTIO
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
	cin >> n;
	for (int i = 0; i < n; ++i) {
		int x, y;
		ll v;
		cin >> x >> y >> v;
		ad.emplace_back(x - 1, 100 + y - 1, -v);
	}
	cin >> m;
	for (int i = 0; i < 200; ++i)
		rb[i] = n, lb[i] = -n;
	int mx = n;
	for (int i = 0; i < m; ++i) {
		char t;
		int a, b;
		cin >> t >> a >> b;
		--a;
		if (t == 'L') {
			if (a == 99)
				mx = min(mx, b);
			else
				lb[a + 1] = max(lb[a + 1], -b);
		}
		else if (t == 'R') {
			if (a == 0)
				mx = min(mx, b);
			else 
				rb[a] = min(rb[a], b);
		}
		else if (t == 'D') {
			if (a == 99)
				mx = min(mx, b);
			else
				rb[100 + a + 1] = min(rb[100 + a + 1], b);
		}
		else {
			if (a == 0)
				mx = min(mx, b);
			else
				lb[100 + a] = max(lb[100 + a], -b);
		}
	}
	ll ans = 0;
	s = 200;
	t = 201;
	for (int k = 1; k <= mx; ++k) {
		clear();
		int fl = 0;
		for (int i = 0; i < 200; ++i)
			if (lb[i] + k > rb[i])
				fl = 1;
		if (fl)
			continue;
		add_edge(s, 0, k, 0); 
		add_edge(199, t, k, 0);
		int sum = k;
		for (int i = 0; i < 99; ++i) {
			int l = max(0, lb[i + 1] + k);
			int r = min(k, rb[i + 1]);
			add_edge(i, i + 1, r - l, 0);
			add_edge(s, i + 1, l, 0);
			add_edge(i, t, l, 0);
			sum += l;
		}
		for (int i = 100; i < 199; ++i) {
			int l = max(0, lb[i + 1] + k);
			int r = min(k, rb[i + 1]);
			add_edge(i, i + 1, r - l, 0);
			add_edge(s, i + 1, l, 0);
			add_edge(i, t, l, 0);
			sum += l;
		}
		for (auto e: ad) {
			int a, b; ll v;
			tie(a, b, v) = e;
			add_edge(a, b, 1, v);
		}
		pair<int, ll> x = flow();
		if (x.first == sum)
			ans = min(ans, x.second);
	}
	cout << -ans << "\n";
	return 0;
}




Measured memory_bytes: 384