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



class min_cost_flow {
	struct ed {
		int rev;
		long long int cost;
		long long int cap;
		int to;
		ed(int rev_, long long int cost_, long long int cap_, int to_) {
			rev = rev_;
			cost = cost_;
			cap = cap_;
			to = to_;
		}
	};
	vector<long long int> prevv;
	vector<long long int> pot;
	vector<long long int> dist;
	vector<long long int> preve;  //直前の辺
	vector<vector<ed> > g;  //graph
	int sizee = 0;
public:
	long long int must;
	min_cost_flow(int n2 = 0) {
		if (n2 == 0) {
			return;
		}
		must = 0;
		sizee = n2;
		prevv.resize(n2);
		dist.resize(n2);
		pot.resize(n2);
		g.resize(n2);
		preve.resize(n2);
	}
	int sss;
	int ttt;
	void resize(int n2) {
		n2 += 3;
		sss = n2 - 2;
		ttt = n2 - 1;
		sizee = n2;
		must = 0;
		prevv.resize(n2);
		dist.resize(n2);
		pot.resize(n2);
		g.resize(n2);
		preve.resize(n2);
	}
	void clear() {
		sizee = 0;
		prevv.clear();
		dist.clear();
		pot.clear();
		g.clear();
		preve.clear();
	}
	int size() {
		return sizee;
	}
	void add(int from_, int to_, long long int cap_, long long int cost_) {
		g[from_].push_back(ed(g[to_].size(), cost_, cap_, to_));
		g[to_].push_back(ed(g[from_].size() - 1, -cost_, 0, from_));
	}
	void add_edge(int from_, int to_, long long int dc,long long int uc, long long int cost_) {
		add(from_, to_, uc - dc, cost_);
		add(sss, to_, dc, 0);
		add(from_, ttt, dc, 0);
		must += dc;
	}
	
	long long int min_cost(int s, int t, long long int f) {
		const long long int INF = -1000000001000000000LL;
		add(sss, s, f, 0);
		add(t, ttt, f, 0);
		s = sss;
		t = ttt;
		f += must;
		long long int res = 0;
		fill(pot.begin(), pot.end(), 0);
		while (f > 0) {
			fill(dist.begin(), dist.end(),INF );
			queue<int> q;
			q.push(s);
			dist[s] = 0;
			while (!q.empty()) {
				int kari = q.front();
				q.pop();
				for (int i = 0; i < g[kari].size(); i++) {
					ed &e = g[kari][i];
					if (e.cap > 0 && (dist[e.to] == INF || dist[e.to] > dist[kari] + e.cost + pot[kari] - pot[e.to])) {
						dist[e.to] = dist[kari] + e.cost + pot[kari] - pot[e.to];
						prevv[e.to] = kari;
						preve[e.to] = i;
						q.push(e.to);
					}
				}
			}
			if (dist[t] == INF) {
				return 114514;  //error
			}
			for (int i = 0; i < dist.size(); i++) {
				pot[i] += dist[i];
			}
			long long int mint = f;
			for (int v = t; v != s; v = prevv[v]) {
				mint = min(mint, g[prevv[v]][preve[v]].cap);
			}
			f -= mint;
			res += mint * pot[t];
			for (int v = t; v != s; v = prevv[v]) {
				ed &e = g[prevv[v]][preve[v]];
				e.cap -= mint;
				g[v][e.rev].cap += mint;
			}
		}
		return res;
	}
};

int n;

struct st {
	int a;
	int b;
	long long int c;
};
vector<st> v;

char buf[3];

struct query {
	char z;
	int a;
	int b;
};
vector<query> vq;

#define MAX 115

int limx[MAX];
int limy[MAX];
int dwx[MAX];
int dwy[MAX];

int enx[MAX];
int eny[MAX];

min_cost_flow mf;

long long int calc(int b) {
	mf = min_cost_flow();
	for (int i = 0; i < MAX; i++) {
		limx[i] = limy[i] = b;
		dwx[i] = dwy[i] = 0;
	}
	for (int i = 0; i < vq.size(); i++) {
		if (vq[i].z == 'L') {
			limx[vq[i].a] = min(limx[vq[i].a], vq[i].b);
			continue;
		}
		if (vq[i].z == 'D') {
			limy[vq[i].a] = min(limy[vq[i].a], vq[i].b);
			continue;
		}
		if (vq[i].z == 'R') {
			int sel = b - vq[i].b;
			if (sel >= 0) {
				dwx[vq[i].a-1] = max(dwx[vq[i].a-1], sel);
			}
			continue;
		}
		if (vq[i].z == 'U') {
			int sel = b - vq[i].b;
			if (sel >= 0) {
				dwy[vq[i].a-1] = max(dwy[vq[i].a-1], sel);
			}
		}
	}
	mf.resize(MAX * 3);
	int ord = 0;
	int star=ord++;
	int en=ord++;
	{
		int dx = 0;
		int ux = b;
		int p = star;
		for (int j = MAX - 1; j >= 0; j--) {
			ux = limx[j];// min(ux, limx[j]);
			dx = dwx[j];
			if (dx > ux)return 114514;
			int cur = ord++;
			mf.add_edge(p, cur, dx, ux, 0);
			enx[j] = cur;
			p = cur;
		}
	}
	{
		int dy = 0;
		int uy = b;
		int p = en;
		for (int j = MAX-1; j>=0; j--) {
			uy = limy[j];// min(uy, limy[j]);
			dy = dwy[j];
			if (dy > uy)return 114514;;
			int cur = ord++;
			mf.add_edge(cur,p, dy, uy, 0);
			eny[j] = cur;
			p = cur;
		}
	}
	for (int i = 0; i < v.size(); i++) {
		mf.add_edge(enx[v[i].a], eny[v[i].b], 0, 1, -v[i].c);
	}
	long long int cost = mf.min_cost(star, en, b);
	return cost;
}


int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		int a, b;
		long long int c;
		scanf("%d%d%lld", &a, &b, &c);
		v.push_back({ a,b,c });
	}
	int q;
	cin >> q;
	for (int i = 1; i <= q; i++) {
		int a, b;
		scanf("%s", buf);
		char ty = buf[0];
		scanf("%d%d", &a, &b);
		vq.push_back({ buf[0],a,b });
	}
	long long int ans = 0;
	for (int i = 1; i <= n; i++) {
		long long int w=calc(i);
		//cout << i << " " << w << endl;
		if (w == 114514)break;
		ans = min(ans, w);
	}
	printf("%lld\n", -ans);
	return 0;
}

Measured memory_bytes: 384