#include<bits/stdc++.h>
typedef long long ll;
typedef std::pair<ll,int> pr;
const int maxn = 10010;
ll x[maxn], y[maxn], v[maxn], a[maxn], b[maxn];
char t[maxn]; 
int n,m;
namespace mcmf{
    const int maxn = 10010,maxm = 1001000;
    struct T{ int to,nxt,v; ll f; } way[maxm << 1];;
    int h[maxn],num = 1;
    inline void link(int x,int y,int v,ll f){
        way[++num]={y,h[x],v,f},h[x]=num;
        way[++num]={x,h[y],0,-f},h[y]=num;
    }
    ll d[maxn],dis[maxn]; int vis[maxn],fr[maxn];
    inline void bellmanford(int s,int t){
        std::queue<int> q;
		std::fill(d + s,d + t + 1,1e18);
        std::fill(vis + s,vis + t + 1,0);
        for(d[s] = 0,q.push(s);!q.empty();){
            int t = q.front(); q.pop(); vis[t] = 0;
            for(int i=h[t];i;i=way[i].nxt) 
                if(way[i].v && d[way[i].to] > d[t] + way[i].f){
                    d[way[i].to] = d[t] + way[i].f;
                    if(!vis[way[i].to]) vis[way[i].to]=1,q.push(way[i].to);
                }
        }
    }
    inline bool dijkstra(int s,int t){
        std::priority_queue<pr,std::vector<pr>,std::greater<pr>> q;
        std::fill(dis + s,dis + t + 1,1e18);
        std::fill(vis + s,vis + t + 1,0);
        for(dis[s] = 0,q.push(pr(0,s));!q.empty();){
            pr t=q.top(); q.pop(); if(vis[t.second]) continue; vis[t.second] = 1;
            for(int i=h[t.second];i;i=way[i].nxt){
                const ll v = way[i].f + d[t.second] - d[way[i].to];
                if(way[i].v && dis[way[i].to] > dis[t.second] + v){
                    dis[way[i].to] = dis[t.second] + v; fr[way[i].to] = i;
                    q.push(pr(dis[way[i].to],way[i].to));
                }
            }
        }
        return dis[t] < 9e17;
    }
    inline std::pair<ll,ll> ek(int s,int t){
        bellmanford(s,t); ll flow = 0,cost = 0;
        while(dijkstra(s,t)){
            ll sum = 0,fl = 1e18;
            for(int i=fr[t];i;i=fr[way[i^1].to])
                fl = std::min<ll>(way[i].v,fl), sum += way[i].f;
            flow += fl,cost += fl * sum;
            for(int i=fr[t];i;i=fr[way[i^1].to]) way[i].v -= fl,way[i ^ 1].v += fl;
            for(int i=s;i<=t;++i) d[i] += dis[i];
        }
		std::fill(h + s,h + t + 1,0);
        return {flow,cost};
    }
}
int lx[maxn], rx[maxn];
int ly[maxn], ry[maxn];
inline void up(int & x,int y){ if(x < y) x = y; }
inline void down(int & x,int y){ if(x > y) x = y; }
int main(){
    std::ios::sync_with_stdio(false),std::cin.tie(0);
    std::cin >> n;
	for(int i = 1;i <= n;++i) std::cin >> x[i] >> y[i] >> v[i];
	std::cin >> m;
	for(int i = 1;i <= m;++i) std::cin >> t[i] >> a[i] >> b[i];
	ll ans = 0;
	for(int cnt = 1;cnt <= n;++cnt) {
		for(int i = 0;i <= cnt + 1;++i) lx[i] = ly[i] = 0, rx[i] = ry[i] = 1e9;
		for(int i = 1;i <= m;++i) if(b[i] < cnt) {
			if(t[i] == 'L') up(lx[b[i] + 1], a[i] + 1);
			if(t[i] == 'R') down(rx[cnt - b[i]], a[i] - 1);
			if(t[i] == 'D') up(ly[b[i] + 1], a[i] + 1);
			if(t[i] == 'U') down(ry[cnt - b[i]], a[i] - 1);
		}
		for(int i = cnt;i >= 1;--i) down(rx[i], rx[i + 1]), down(ry[i], ry[i + 1]);
		for(int i = 1;i <= cnt;++i) up(lx[i], lx[i - 1]), up(ly[i], ly[i - 1]);
		mcmf::num = 1;
		using mcmf::link;
		for(int j = 1;j <= n;++j) link(j + cnt,j + cnt + n,1,-v[j]);
		for(int i = 1;i <= cnt;++i) {
			link(0, i, 1, 0), link(i + cnt + n + n,cnt + n + n + cnt + 1, 1, 0);
			for(int j = 1;j <= n;++j) if(lx[i] <= x[j] && x[j] <= rx[i]) link(i, j + cnt, 1, 0);
			for(int j = 1;j <= n;++j) if(ly[i] <= y[j] && y[j] <= ry[i]) link(j + cnt + n, i + cnt + n + n, 1, 0);
		}
		auto it = mcmf::ek(0,cnt + n + n + cnt + 1);
		ans = std::max(ans, - it.second);
	}
	std::cout << ans << '\n';
}


Measured memory_bytes: 768