#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 400 , INF = 0x3f3f3f3f;
int n,m,x[N],y[N],a[N],b[N],u[N],d[N],l[N],r[N]; char op[N];
int t(1),Head[N],vis[N],S,T; deque <int> q; ll Delta,dis[N],v[N],Ans;
struct Edge { int u,v,next,val; ll cos; } e[N*N*4];
template<class T> inline T Read(void)
{
    T x = 0; bool w = 0; char ch = ' ';
    while ( !isdigit(ch) ) w |= ch == '-' , ch = getchar();
    while ( isdigit(ch) ) x = x * 10 + ch - 48 , ch = getchar();
    return w ? -x : x;
}
inline void Input(void)
{
    n = Read<int>();
    for (int i = 1; i <= n; i++)
        x[i] = Read<int>() , y[i] = Read<int>() , v[i] = Read<ll>();
    m = Read<int>();
    for (int i = 1; i <= m; i++)
    {
        char c = ' ';
        while ( isspace(c) ) c = getchar();
        op[i] = c , a[i] = Read<int>() , b[i] = Read<int>();
    }
}
inline void Insert(int x,int y,ll c,int v)
{
    e[++t] = (Edge){ x , y , Head[x] , v , c } , Head[x] = t;
    e[++t] = (Edge){ y , x , Head[y] , 0 , -c } , Head[y] = t;
}
inline void Build(int k)
{
    for (int i = 1; i <= k; i++)
        u[i] = r[i] = INF , l[i] = d[i] = 0;
    for (int i = 1; i <= m; i++)
        if ( b[i] < k )
        {
            if ( op[i] == 'L' ) l[b[i]+1] = max( l[b[i]+1] , a[i] + 1 );
            if ( op[i] == 'R' ) r[k-b[i]] = min( r[k-b[i]] , a[i] - 1 );
            if ( op[i] == 'D' ) d[b[i]+1] = max( d[b[i]+1] , a[i] + 1 );
            if ( op[i] == 'U' ) u[k-b[i]] = min( u[k-b[i]] , a[i] - 1 );
            // if ( op[i] == 'L' ) l[b[i]+1] = a[i] + 1;
            // if ( op[i] == 'R' ) r[k-b[i]] = a[i] - 1;
            // if ( op[i] == 'D' ) d[b[i]+1] = a[i] + 1;
            // if ( op[i] == 'U' ) u[k-b[i]] = a[i] - 1;
        }
    for (int i = 2; i <= k; i++) l[i] = max( l[i] , l[i-1] ) , d[i] = max( d[i] , d[i-1] );
    for (int i = k-1; i >= 1; i--) r[i] = min( r[i] , r[i+1] ) , u[i] = min( u[i] , u[i+1] );
    memset( Head , 0 , sizeof Head );
    S = ( n + k ) << 1 | 1 , T = ( n + k + 1 ) * 2 , t = 1 , Delta = 0;
    for (int i = 1; i <= n; i++) Insert( i , i+n , v[i] , 1 );
    for (int i = 1; i <= k; i++)
    {
        Insert( S , n*2+i , 0 , 1 ) , Insert( n*2+k+i , T , 0 , 1 );
        for (int j = 1; j <= n; j++)
        {
            if ( l[i] <= x[j] && x[j] <= r[i] ) Insert( n*2+i , j , 0 , 1 );
            if ( d[i] <= y[j] && y[j] <= u[i] ) Insert( j+n , n*2+k+i , 0 , 1 );
        }
    }
    // printf( "t = %d\n" , t );
}
inline bool Relabel(void)
{
    memset( dis , 0xcf , sizeof dis );
    memset( vis , 0x00 , sizeof vis );
    dis[T] = 0 , vis[T] = 1 , q.push_back(T);
    while ( !q.empty() )
    {
        // puts("SPFAing");
        int x = q.front(); q.pop_front() , vis[x] = 0;
        if ( q.size() > 1 && dis[q.front()] < dis[q.back()] )
            swap( q.front() , q.back() );
        for (int i = Head[x] , y; i; i = e[i].next)
            if ( e[i^1].val && dis[ y = e[i].v ] < dis[x] + e[i^1].cos )
            {
                dis[y] = dis[x] + e[i^1].cos;
                // printf( "dis[%d] = %lld\n" , y , dis[y] );
                if ( vis[y] ) continue;
                vis[y] = true , q.push_back(y);
                if ( q.size() > 1 && dis[q.front()] < dis[q.back()] )
                    swap( q.front() , q.back() );
            }
    }
    // printf( "d[%d] = %lld\n" , S , dis[S] );
    return dis[S] != dis[0];
}
inline int Dinic(int x,int flow)
{
    if ( x == T || !flow ) return flow;
    int residue = flow; vis[x] = true;
    for (int i = Head[x] , y; i; i = e[i].next)
        if ( e[i].val && !vis[ y = e[i].v ] && !e[i].cos )
        {
            int k = Dinic( y , min( e[i].val , residue ) );
            e[i].val -= k , e[i^1].val += k;
            if ( ( residue -= k ) == 0 ) break;
        }
    return flow - residue;
}
inline pair<int,ll> PrimalDual(void)
{
    int Maxflow = 0 , Flow = 0; ll Maxcost = 0;
    while ( Relabel() )
    {
        for (int i = 2; i <= t; i++)
            e[i].cos += dis[e[i].v] - dis[e[i].u];
        Delta += dis[S] , memset( vis , 0 , sizeof vis );
        // printf( "Delta = %lld\n" , Delta );
        while ( Flow = Dinic( S , INF ) )
            Maxflow += Flow , Maxcost += 1LL * Flow * Delta ,
            memset( vis , 0 , sizeof vis ) /*, printf( "Dinicing Flow = %d\n" , Flow ) */;
    }
    return make_pair( Maxflow , Maxcost );
}
int main(void)
{
    Input();
    for (int i = 1; i <= n; i++)
        Build(i) , Ans = max( Ans , PrimalDual().second );
    printf( "%lld\n" , Ans );
    return 0;
}


Measured memory_bytes: 768