#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define MAXN 100005
#define eps 1e-10
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 + c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
struct node {
    int to,next,cap;int64 val;
}E[1000005];
int sumE,head[505],a[330],b[330],x[85],y[85],N,M;
int L[2][85],R[2][85],S,T,f;
int64 val[85],res,ans,ex;
bool vis[505];
char s[330][2];
void add(int u,int v,int c,int64 a) {
    E[++sumE].to = v;
    E[sumE].next = head[u];
    E[sumE].cap = c;
    E[sumE].val = a;
    head[u] = sumE;
}
void addtwo(int u,int v,int c,int64 a) {
    add(u,v,c,a);
    add(v,u,0,-a);
}
void build(int K) {
    sumE = 1;memset(head,0,sizeof(head));
    for(int i = 1 ; i <= N ; ++i) L[0][i] = L[1][i] = 1,R[0][i] = R[1][i] = 100;
    for(int i = 1 ; i <= M ; ++i) {
        if(b[i] >= K) continue;
        if(s[i][0] == 'L') {
            L[0][b[i] + 1] = max(L[0][b[i] + 1],a[i] + 1);
        }
        else if(s[i][0] == 'R') {
            R[0][K - b[i]] = min(R[0][K - b[i]],a[i] - 1);
        }
        else if(s[i][0] == 'D') {
            L[1][b[i] + 1] = max(L[1][b[i] + 1],a[i] + 1);
        }
        else if(s[i][0] == 'U') {
            R[1][K - b[i]] = min(R[1][K - b[i]],a[i] - 1);
        }
    }
    for(int i = 2 ; i <= K ; ++i) {
    	L[0][i] = max(L[0][i - 1],L[0][i]);
    	L[1][i] = max(L[1][i - 1],L[1][i]);
    }
    for(int i = K - 1 ; i >= 1 ; --i) {
    	R[0][i] = min(R[0][i + 1],R[0][i]);
    	R[1][i] = min(R[1][i + 1],R[1][i]);
    }
    S = 1;T = 2 * K + 2 * N + 2;
    for(int i = 1 ; i <= K ; ++i) {
    	addtwo(S,i + 1,1,0);
    	addtwo(i + K + 2 * N + 1,T,1,0);
    	for(int j = 1 ; j <= N ; ++j) {
    	    if(x[j] >= L[0][i] && x[j] <= R[0][i]) {
        		addtwo(i + 1,K + j + 1,1,0);
    	    }
    	    if(y[j] >= L[1][i] && y[j] <= R[1][i]) {
        		addtwo(K + N + j + 1,i + K + 2 * N + 1,1,0);
    	    }
    	}
    }
    for(int i = 1 ; i <= N ; ++i) {
        addtwo(K + i + 1,K + N + i + 1,1,val[i]);
    }

}
int maxflow(int u,int aug) {
    if(u == T) {
    	res += ex * aug;
        f += aug;
    	return aug;
    }
    int flow = 0;
    vis[u] = 1;
    for(int i = head[u] ; i ; i = E[i].next) {
        int v = E[i].to;
    	if(E[i].cap > 0 && !vis[v] && E[i].val == 0) {
    	    int t = maxflow(v,min(E[i].cap,aug - flow));
    	    flow += t;
    	    E[i].cap -= t;
    	    E[i ^ 1].cap += t;
    	}
    }
    return flow;
}
bool modlabel() {
    int64 p = -1e18;
    for(int u = S ; u <= T ; ++u) {
    	if(vis[u]) {
    	    for(int i = head[u] ; i ; i = E[i].next) {
        		int v = E[i].to;
        		if(!vis[v] && E[i].cap > 0 && E[i].val > p) p = E[i].val;
    	    }
    	}
    }
    if(p == -1e18) return false;
    ex += p;
    for(int u = S ; u <= T ; ++u) {
    	if(vis[u]) {
    	    for(int i = head[u] ; i ; i = E[i].next) {
        		E[i].val -= p;
        		E[i ^ 1].val += p;
    	    }
    	}
    }
    return true;
}
void Init() {
    read(N);
    for(int i = 1 ; i <= N ; ++i) {
    	read(x[i]);read(y[i]);read(val[i]);
    }
    read(M);
    for(int i = 1 ; i <= M ; ++i) {
    	scanf("%s",s[i]);read(a[i]);read(b[i]);
    }
}
void Solve() {
    ans = 0;
    for(int i = 1 ; i <= N ; ++i) {
    	build(i);
    	res = 0;ex = 0;
        f = 0;
    	do {
    	    do {
                memset(vis,0,sizeof(vis));
    	    }while(maxflow(1,i));
    	}while(modlabel());
        if(f == i) ans = max(ans,res);
    }
    out(ans);enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Init();
    Solve();
}


Measured memory_bytes: 640