#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MN 100
#define S 0
#define T 201
#define SS 202
#define TT 203
#define INF 2000000000
inline ll read()
{
    ll x=0,f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-') f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    return x*f;
}
char ch[5];
int n,m,d[MN+5],u[MN+5],l[MN+5],r[MN+5],rk[MN+5],xx[MN+5],yy[MN+5];
ll v[MN+5],ans=0,now,pi,dis[TT+5];

bool inq[TT+5],mark[TT+5];
int cnt,head[TT+5],q[TT+5],top,tail,in[TT+5];
struct edge{int to,next,w;ll c;}e[T*T];
inline void ins(int f,int t,int w,ll v)
{
    e[++cnt]=(edge){t,head[f],w, v};head[f]=cnt;
    e[++cnt]=(edge){f,head[t],0,-v};head[t]=cnt;
}
inline void Ins(int f,int t,int L,int R,ll v){if(L>R)--now;in[t]+=L;in[f]-=L;if(R>L)ins(f,t,R-L,v);}
inline int nxt(int x){return ++x>TT?0:x;}
inline int lst(int x){return --x<0?TT:x;}
bool Label(int from,int to)
{
    memset(dis,63,sizeof(dis));dis[to]=0;
    q[top=1]=to;tail=0;inq[to]=1;
    while(top!=tail)
    {
        int x=q[tail=nxt(tail)];
        for(int i=head[x];i;i=e[i].next)
            if(e[i^1].w&&dis[x]+e[i^1].c<dis[e[i].to])
            {
                dis[e[i].to]=dis[x]+e[i^1].c;
                if(!inq[e[i].to])
                {
                    inq[e[i].to]=1;
                    if(dis[e[i].to]<dis[nxt(tail)]) q[tail]=e[i].to,tail=lst(tail);
                    else q[top=nxt(top)]=e[i].to;
                }
            }
        inq[x]=0;
    }
    if(dis[from]>1e17) return false;
    for(int i=1;i<=TT;++i) for(int j=head[i];j;j=e[j].next)
        e[j].c+=dis[e[j].to]-dis[i];
    pi+=dis[from];return true;
}

int dfs(int x,int to,int f)
{
    if(x==to) return now+=pi*f,f;mark[x]=1;
    int used=0;
    for(int i=head[x];i;i=e[i].next)
        if(!mark[e[i].to]&&!e[i].c&&e[i].w)
        {
            int w=dfs(e[i].to,to,min(f-used,e[i].w));
            e[i].w-=w;e[i^1].w+=w;
            used+=w;if(used==f) return f;
        }
    return used;
}

int main()
{
    n=read();
    for(int i=1;i<=MN;++i) d[i]=u[i]=l[i]=r[i]=n;
    for(int i=1;i<=n;++i)  
        xx[i]=read(),yy[i]=read(),v[i]=read();
    m=read();
    for(int i=1,j,k;i<=m;++i)
    {
        scanf("%s%d%d",ch+1,&j,&k);
        if(ch[1]=='L') l[j]=k; if(ch[1]=='R') r[j]=k;
        if(ch[1]=='U') u[j]=k; if(ch[1]=='D') d[j]=k;
    }
    for(int i=2;i<=MN;++i) r[i]=min(r[i],r[i-1]),u[i]=min(u[i],u[i-1]);
    for(int i=MN;--i>=1;)  l[i]=min(l[i],l[i+1]),d[i]=min(d[i],d[i+1]);
    for(int t=1;t<=min(min(l[MN],d[MN]),min(u[1],r[1]));++t)
    {
        cnt=1;memset(head,0,sizeof(head));now=pi=0;
        memset(in,0,sizeof(in));
        for(int i=1;i<=MN;++i) 
        {
            Ins(i==MN?S:i+1,i,max(0,t-r[i+1]),min(t,l[i]),0);
            Ins(MN+i,i==MN?T:MN+i+1,max(0,t-u[i+1]),min(t,d[i]),0);
        }
        if(now!=0) continue;
        for(int i=1;i<=n;++i) Ins(xx[i],yy[i]+MN,0,1,-v[i]+1e15);
        int flow=0,must=0;
        for(int i=S;i<=T;++i) 
        {
            if(in[i]>0) ins(SS,i, in[i],0),must+=in[i];
            if(in[i]<0) ins(i,TT,-in[i],0);
        }
        ins(T,S,INF,0);
        while(Label(SS,TT)) 
            memset(mark,0,sizeof(mark)),flow+=dfs(SS,TT,INF);
        e[cnt].w=e[cnt-1].w=0;
        while(Label(S,T))
            memset(mark,0,sizeof(mark)),flow+=dfs(S,T,INF);
        if(flow==must) ans=max(ans,-now+t*(ll)(1e15));
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256