#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) (((x) < 0)?-(x):(x))
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

using cat = long long;

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

struct Edge
{
    int from, to, capacity;
    cat cost;
};

vector<vector<int>> adj, capacity;
vector<vector<cat>> cost;

const cat INF = (cat)1e18;

void shortest_paths(int n, int v0, vector<cat>& d, vector<int>& p) {
    d.assign(n, INF);
    d[v0] = 0;
    vector<int> m(n, 2);
    deque<int> q;
    q.push_back(v0);
    p.assign(n, -1);

    while (!q.empty()) {
        int u = q.front();
        q.pop_front();
        m[u] = 0;
        for (int v : adj[u]) {
            if (capacity[u][v] > 0 && d[v] > d[u] + cost[u][v]) {
                d[v] = d[u] + cost[u][v];
                p[v] = u;
                if (m[v] == 2) {
                    m[v] = 1;
                    q.push_back(v);
                } else if (m[v] == 0) {
                    m[v] = 1;
                    q.push_front(v);
                }
            }
        }
    }
}

cat min_cost_flow(int N, vector<Edge> edges, int K, int s, int t) {
    adj.assign(N, vector<int>());
    cost.assign(N, vector<cat>(N, 0));
    capacity.assign(N, vector<int>(N, 0));
    for (Edge e : edges) {
        adj[e.from].push_back(e.to);
        adj[e.to].push_back(e.from);
        cost[e.from][e.to] = e.cost;
        cost[e.to][e.from] = -e.cost;
        capacity[e.from][e.to] = e.capacity;
    }

    int flow = 0;
    cat cost_ = 0;
    vector<int> p;
    vector<cat> d;
    while (flow < K) {
        shortest_paths(N, s, d, p);
        if (d[t] == INF)
            break;

        // find max flow on that path
        int f = K - flow;
        int cur = t;
        while (cur != s) {
            f = min(f, capacity[p[cur]][cur]);
            cur = p[cur];
        }

        // apply flow
        flow += f;
        cost_ += f * d[t];
        cur = t;
        while (cur != s) {
            capacity[p[cur]][cur] -= f;
            capacity[cur][p[cur]] += f;
            cur = p[cur];
        }
    }

    // cout << flow << "\n";
    // for (Edge e : edges)
    //     cout << e.from << " " << e.to << " " << e.capacity << " " << e.cost << " " << capacity[e.to][e.from] << "\n";
    if (flow < K)
        return -1;
    else
        return cost_;
}

struct jewel {
	int x, y;
	cat w;
};

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	int N, M;
	cin >> N;
	vector<jewel> J(N);
	for(int i = 0; i < N; i++) cin >> J[i].x >> J[i].y >> J[i].w;
	vector< pair<int, int> > cond[4];
	cin >> M;
	for(int i = 0; i < M; i++) {
		string tp;
		int a, b;
		cin >> tp >> a >> b;
		if(tp == "L") cond[0].push_back({a, b});
		if(tp == "D") cond[1].push_back({a, b});
		if(tp == "R") cond[2].push_back({a-1, b});
		if(tp == "U") cond[3].push_back({a-1, b});
	}
	for(int k = 0; k < 4; k++) {
		sort(begin(cond[k]), end(cond[k]));
		if(k/2 == 0) reverse(begin(cond[k]), end(cond[k]));
		while(true) {
			bool stop = true;
			for(int i = 0; i < (int)cond[k].size(); i++)
				for(int j = 0; j < (int)cond[k].size(); j++) if(i != j)
					if(cond[k][i].ff == cond[k][j].ff && cond[k][i].ss < cond[k][j].ss) {
						cond[k].erase(begin(cond[k])+j);
						stop = false;
						break;
					}
			for(int i = 0; i < (int)cond[k].size(); i++)
				for(int j = i+1; j < (int)cond[k].size(); j++)
					if(cond[k][i].ss <= cond[k][j].ss) {
						cond[k].erase(begin(cond[k])+j);
						stop = false;
						break;
					}
			if(stop) break;
		}
		if(k/2 != 0) reverse(begin(cond[k]), end(cond[k]));
	}
	cat MX = 1e15;
	cat ans = 0;
	for(int K = 1; K <= N; K++) {
		vector<Edge> edges;
		edges.push_back({0, 1, K, 0});
		int V = 2, S = 0;
		bool ok = true;
		vector< pair<int, int> > m[2] = {{{1, 100}}, {}}, b;
		for(int a[2] = {0, 0}; a[0] < (int)cond[0].size() || a[1] < (int)cond[2].size();) {
			int i = 0;
			if(a[0] == (int)cond[0].size()) i = 1;
			else if(a[1] < (int)cond[2].size() && cond[2][a[1]].ff > cond[0][a[0]].ff) i = 1;
			if(i == 1 && K-cond[2][a[1]].ss > 0) {
				edges.push_back({V-1, V, K, 0});
				edges.push_back({V+1, V, K-cond[2][a[1]].ss, MX});
				edges.push_back({V+1, V+2, K, 0});
				edges.push_back({0, V+1, K-cond[2][a[1]].ss, 0});
				b.push_back({V, K-cond[2][a[1]].ss});
				S += K-cond[2][a[1]].ss;
			}
			m[0].push_back({V+2*i, cond[2*i][a[i]].ff});
			edges.push_back({V-1, V+2*i, (i == 0) ? cond[0][a[0]].ss : K, 0});
			V += 1+2*i;
			a[i]++;
		}
		V++;
		reverse(begin(cond[1]), end(cond[1]));
		reverse(begin(cond[3]), end(cond[3]));
		for(int a[2] = {0, 0}; a[0] < (int)cond[1].size() || a[1] < (int)cond[3].size();) {
			int i = 0;
			if(a[0] == (int)cond[1].size()) i = 1;
			else if(a[1] < (int)cond[3].size() && cond[3][a[1]].ff < cond[1][a[0]].ff) i = 1;
			if(i == 1 && K-cond[3][a[1]].ss > 0) {
				edges.push_back({V-1, V, K, 0});
				edges.push_back({V+1, V, K-cond[3][a[1]].ss, MX});
				edges.push_back({V+1, V+2, K, 0});
				edges.push_back({0, V+1, K-cond[3][a[1]].ss, 0});
				b.push_back({V, K-cond[3][a[1]].ss});
				S += K-cond[3][a[1]].ss;
			}
			m[1].push_back({V-1, cond[2*i+1][a[i]].ff});
			edges.push_back({V-1, V+2*i, (i == 0) ? cond[1][a[0]].ss : K, 0});
			V += 1+2*i;
			a[i]++;
		}
		reverse(begin(cond[1]), end(cond[1]));
		reverse(begin(cond[3]), end(cond[3]));
		if(!ok) continue;
		int last = V-1;
		m[1].push_back({last, 100});
		reverse(begin(m[1]), end(m[1]));
		for(int i = 0; i < N; i++) {
			int a[2] = {0, 0};
			while(a[0] < (int)m[0].size()) {
				if(m[0][a[0]].ss < J[i].x) break;
				a[0]++;
			}
			while(a[1] < (int)m[1].size()) {
				if(m[1][a[1]].ss < J[i].y) break;
				a[1]++;
			}
			edges.push_back({m[0][a[0]-1].ff, V, 1, MX-J[i].w});
			edges.push_back({V, m[1][a[1]-1].ff, 1, 0});
			V++;
		}
		edges.push_back({last, V, K, 0});
		for(auto p : b) edges.push_back({p.ff, V, p.ss, 0});
		cat mcf = min_cost_flow(V+1, edges, K+S, 0, V);
		// cout << K << " " << K*MX-mcf << "!\n";
		if(mcf != -1) ans = max(ans, K*MX - mcf);
	}
	cout << ans << "\n";
	return 0;
}

// look at my code
// my code is amazing


Measured memory_bytes: 2816