#include <bits/stdc++.h>

using namespace std;

struct edge
{
	int v,nxt,flow;
	long long w;
}e[500050];

int head[405],ecnt;
long long dep[405];
bool inq[405];
int n,m;
int s,t;
const long long inf = 1e18;

void adde(int u,int v,int fl,long long w)
{
	e[ecnt].v = v;
	e[ecnt].nxt = head[u];
	e[ecnt].flow = fl;
	e[ecnt].w = w;
	head[u] = ecnt ++;
}

void Adde(int u,int v,int fl,long long w)
{
	adde(u,v,fl,w);
	adde(v,u,0,-w);
}

bool spfa()
{
    deque<long long> que;
   	for(int i = 0;i <= t; ++ i)
   		dep[i] = (1ll << 62);
    memset(inq,0,sizeof(inq));
    dep[t] = 0;
    que.push_back(t);
    while(!que.empty())
    {
        long long u = que.front();
        que.pop_front();
        for(long long i = head[u];~i;i = e[i].nxt)
        {
            long long v = e[i].v;
            if(e[i ^ 1].flow && dep[u] - e[i].w < dep[v])
            {
                dep[v] = dep[u] + e[i ^ 1].w;
                if(!inq[v])
                {
                    if(que.empty() || dep[v] < dep[que.front()])
                        que.push_front(v);
                    else
                        que.push_back(v);
                    inq[v] = true;
                }
            }
        }
        inq[u] = false;
    }
    return dep[s] < (1ll << 62);
}

int curedge[405];
long long ans;
bool vis[405];

long long dfs(long long s,long long t,long long flow)
{
    if(s == t)
        return flow;
    long long delta = flow;
    vis[s] = true;
    for(long long i = head[s];~i;i = e[i].nxt)
    {
        long long v = e[i].v;
        if(!vis[v] && dep[v] == dep[s] - e[i].w && e[i].flow)
        {
            //prlong longf("%d %d\n",s,v);
            long long g = dfs(v,t,min((long long)e[i].flow,delta));
            delta -= g;
            ans += g * e[i].w;
            e[i].flow -= g;
            e[i ^ 1].flow += g;
            if(!delta)
                return flow;
        }
    }
    return flow - delta;
}

long long dinic()
{
    long long anss = 0;
    while(spfa())
    {
    	vis[t] = 1;
    	while(vis[t])
    	{
        	memset(vis,0,sizeof(vis));
        	anss += dfs(s,t,inf);
        }
    }
    return anss;
}

int pre[405];

struct stone
{
	int x,y;
	long long vl;
}st[105];

struct Limitation
{
	int a,b;
}L[105],R[105],D[105],U[105];
int lc,rc,dc,uc;
int xl[105],xr[105],yl[105],yr[105];

int main()
{
	int n; scanf("%d",&n);
	for(int i = 1;i <= n; ++ i)
		scanf("%d%d%lld",&st[i].x,&st[i].y,&st[i].vl);
	int m; scanf("%d",&m);
	for(int i = 1;i <= m; ++ i)
	{
		char str[16]; scanf("%s",str + 1);
		if(str[1] == 'L') lc ++,scanf("%d%d",&L[lc].a,&L[lc].b);
		else if(str[1] == 'R') rc ++,scanf("%d%d",&R[rc].a,&R[rc].b);
		else if(str[1] == 'U') uc ++,scanf("%d%d",&U[uc].a,&U[uc].b);
		else dc ++,scanf("%d%d",&D[dc].a,&D[dc].b);
	}
	long long as = 0;
	for(int k = 1;k <= n; ++ k)
	{
		memset(head,-1,sizeof(head));
		ecnt = 0;
		ans = 0;
		s = 0,t = k * 2 + n * 2 + 1;
		for(int i = 1;i <= k; ++ i)
			Adde(s,i,1,0),
			Adde(i + 2 * n + k,t,1,0),
			xl[i] = yl[i] = 0,xr[i] = yr[i] = 100;
		for(int i = 1;i <= lc; ++ i)
			for(int j = L[i].b + 1;j <= k; ++ j)
				xl[j] = max(xl[j],L[i].a + 1);
		for(int i = 1;i <= rc; ++ i)
			for(int j = k - R[i].b;j >= 1; -- j)
				xr[j] = min(xr[j],R[i].a - 1);
		for(int i = 1;i <= dc; ++ i)
			for(int j = D[i].b + 1;j <= k; ++ j)
				yl[j] = max(yl[j],D[i].a + 1);
		for(int i = 1;i <= uc; ++ i)
			for(int j = k - U[i].b;j >= 1; -- j)
				yr[j] = min(yr[j],U[i].a - 1);
		for(int i = 1;i <= n; ++ i)
		{
			Adde(i + k,i + n + k,1,-st[i].vl);
			for(int j = 1;j <= k; ++ j)
			{
				if(yl[j] <= st[i].y && st[i].y <= yr[j])
					Adde(i + n + k,j + 2 * n + k,1,0);
				if(xl[j] <= st[i].x && st[i].x <= xr[j])
					Adde(j,i + k,1,0);
			}
		}
		dinic(); as = max(as,-ans);
	}
	printf("%lld\n",as);
}

Measured memory_bytes: 4200