#include<bits/stdc++.h>
using namespace std;
#define MAXNUM 333
typedef long long ll;
#define rep(i,s,t) for(int i=s;i<t;i++)
const ll inf=1e18;
#define pii pair<int,int>
typedef struct edge {
    int ver;ll cost, flow;
}edge;
int nodenum, edgenum;
edge e[111111];
vector<int> v[MAXNUM];
ll dis[MAXNUM];int pre[MAXNUM];
int preedge[MAXNUM];ll minflow[MAXNUM];
bool isused[MAXNUM];
int stnode, ednode;
ll cost, flow;
bool spfa()
{
    for (int i = 1; i <= nodenum; i++)
        dis[i] = inf, isused[i] = 0;
    queue<int> q;
    q.push(stnode);
    isused[stnode] = 1, minflow[stnode] = inf;
    dis[stnode] = 0;
    while (!q.empty())
    {
        int now = q.front();
        q.pop();
        isused[now]=0;
        for (int i : v[now])
        {
            if (!e[i].flow)
                continue;
            int k = e[i].ver;
            if (dis[k] > dis[now] + e[i].cost)
            {
                dis[k] = dis[now] + e[i].cost;
                pre[k] = now;
                preedge[k] = i;
                minflow[k] = min(minflow[now], e[i].flow);
                if (!isused[k])
                    q.push(k), isused[k] = 1;
            }
        }
    }
    if (dis[ednode] == inf)
        return 0;
    return 1;
}
void addedge(int a, int b, ll f, ll c)
{
    e[edgenum].ver = b,e[edgenum].cost = c,e[edgenum].flow = f;v[a].push_back(edgenum++);
    e[edgenum].ver = a;e[edgenum].cost = -c;e[edgenum].flow = 0;v[b].push_back(edgenum++);
}
void mincostflow()
{
    cost = flow = 0;
    while (spfa())
    {
        ll f = minflow[ednode];
        for (int i = ednode; i != stnode; i = pre[i])
        {
            int k = preedge[i];
            e[k].flow -= f;
            e[k ^ 1].flow += f;
        }
        flow += f;
        cost += dis[ednode] * f;
    }
}
int toflow[MAXNUM];ll sumcost;
void add(int a, int b, ll maxf, int minf,ll c)
{
    ll k = maxf - minf;
    addedge(a, b, k, c);
    toflow[a] -= minf;
    toflow[b] += minf, sumcost += minf * c;
}
ll max_limit_flow()
{
    v[nodenum + 1].clear(); v[nodenum + 2].clear();
    add(ednode, stnode, inf, 0,0);ll sumnow=0;
    int k=edgenum;
    for (int i = 1; i <= nodenum; i++)
    {
        if (toflow[i] < 0)
            addedge(i,nodenum+2, -toflow[i],0);
        else addedge(nodenum + 1, i, toflow[i],0),sumnow+=toflow[i];
    }
    int start = stnode, end = ednode;
    stnode = nodenum + 1, ednode = nodenum + 2;
    nodenum += 2;
    mincostflow();
    if (sumnow != flow)
        return 1111;
    stnode = start, ednode = end,sumcost+=cost;
    nodenum -= 2;
    e[k].flow = e[k ^ 1].flow = 0;
    nodenum -= 2;
    for(int i:v[nodenum+1])
        e[i].flow = e[i ^ 1].flow = 0;
    for(int i:v[nodenum+2])
        e[i].flow = e[i ^ 1].flow = 0;
    mincostflow();
    return cost + sumcost;
}
int n,m;
int upx[111],downx[111],upy[111],downy[111];
pii item[111];ll w[111];
ll getres(int k)
{
    cost=sumcost=flow=0;nodenum=204+2;edgenum=2;
    rep(i,1,nodenum+1)toflow[i]=0,v[i].clear();
    stnode=nodenum,ednode=nodenum-1;
    add(stnode,1,k,k,0),add(204,ednode,k,k,0);
    rep(i,0,101)add(i+1,i+2,upx[i+1],max(0,k-downx[i]),0);
    rep(i,0,101)add(i+102+1,i+102+2,downy[i],max(0,k-upy[i+1]),0);
    rep(i,1,n+1)add(item[i].first+1,item[i].second+1+102,1,0,-w[i]);
    return -max_limit_flow();
}
char tmps[3];
int main()
{
    scanf("%d",&n);
    rep(i,1,n+1)scanf("%d%d%lld",&item[i].first,&item[i].second,&w[i]);
    int m,a,b;scanf("%d",&m);
    rep(i,0,102)
        upx[i]=downy[i]=n+2,downx[i]=upy[i]=n+2;
    rep(i,1,m+1)
    {
        scanf("%s%d%d",tmps,&a,&b);
        if(tmps[0]=='L')downx[a]=min(downx[a],b);
        else if(tmps[0]=='R')upx[a]=min(upx[a],b);
        else if(tmps[0]=='U')upy[a]=min(upy[a],b);
        else downy[a]=min(downy[a],b);
    }
    ll res=0;
    rep(i,1,n+1)
        res=max(res,getres(i));
    printf("%lld\n",res);
}