#include<bits/stdc++.h>
#define IL inline
#define _ 1005
#define ll long long
#define RG register
using namespace std ;

IL ll gi() {
	RG ll data = 0 , fu = 1 ; RG char ch = 0 ;
	while(ch != '-' && (ch < '0' || ch > '9')) ch = getchar() ; if(ch == '-') fu = -1 , ch = getchar() ;
	while('0' <= ch && ch <= '9') data = (data << 1) + (data << 3) + (ch ^ 48) , ch = getchar() ; return data * fu ;
}

const ll extra = 1e15 ;
const ll inf = 1e18 ;

struct _Edge{int to , next , flow ; ll cost ; } Edge[_ * _] ; int head[_] , cur[_] , CNT ;
IL void AddEdge(int u , int v , int fl , ll cs) {
	//cout << u << " ------------> " << v << " ; flow = " << fl << " , cost = " << cs << endl ;
	Edge[++ CNT] = (_Edge){v , head[u] , fl , cs} ; head[u] = CNT ;
	Edge[++ CNT] = (_Edge){u , head[v] , 0 , -cs} ; head[v] = CNT ; return ; 
}
struct Point{int x,y ; ll v ; } p[_] ; bool vis[_] ;
struct Limit{char t ; int a,b ; } q[_] ;
ll dis[_],Cost,Ans ; int L[_],U[_],D[_],R[_],n,m,S,T,K,Flow,oo ;

IL bool bfs() {
	queue<int> Q ; 
	for(int i = 1; i <= T; i ++) dis[i] = inf , vis[i] = false ;
	Q.push(S) ; vis[S] = true ; dis[S] = 0 ;
	while(!Q.empty()) {
		int u = Q.front() ; Q.pop() ;
		for(int e = head[u] ; e ; e = Edge[e].next) {
			int v = Edge[e].to ;
			if(dis[v] > dis[u] + Edge[e].cost && Edge[e].flow > 0) {
				dis[v] = dis[u] + Edge[e].cost ;
				if(!vis[v]) vis[v] = true , Q.push(v) ;
			}
		}vis[u] = false ; 
	}return dis[T] != inf ; 
}
int dfs(int u , int Lim) {
	if(u == T || !Lim) return Lim ;
	ll flow = 0 , f = 0 ; vis[u] = true ;
	for(int &e = cur[u] ; e ; e = Edge[e].next) {
		int v = Edge[e].to ;
		if(!vis[v] && dis[v]==dis[u]+Edge[e].cost && (f = dfs(v,min(Lim,Edge[e].flow))) > 0) {
			flow += f ; Lim -= f ; Edge[e].flow -= f ; Edge[e ^ 1].flow += f ;
			Cost += 1ll * flow * Edge[e].cost ;
			if(!Lim) break ;
		}
	}if(!flow) dis[u] = -1 ; vis[u] = false ; return flow ; 
}
	
IL void solve() {
	for(int i = 1; i <= T; i ++) head[i] = 0 ; CNT = 1 ; oo = 0 ;
	for(int i = 1; i <= K ; i ++) L[i] = U[i] = 0 , R[i] = D[i] = 1989 ;
	for(int i = 1; i <= m ; i ++)
		if(q[i].b < K) {
			if(q[i].t == 'L') L[q[i].b + 1] = max(L[q[i].b + 1] , q[i].a + 1) ;
			else if(q[i].t == 'R') R[K - q[i].b] = min(R[K - q[i].b] , q[i].a - 1) ;
			else if(q[i].t == 'U') U[q[i].b + 1] = max(U[q[i].b + 1] , q[i].a + 1) ;
			else if(q[i].t == 'D') D[K - q[i].b] = min(D[K - q[i].b] , q[i].a - 1) ;
		}
	for(int i = 2; i <= K; i ++) L[i] = max(L[i] , L[i - 1]) ;
	for(int i = K - 1; i >= 1; i --) R[i] = min(R[i] , R[i + 1]) ;
	for(int i = 2; i <= K; i ++) U[i] = max(U[i] , U[i - 1]) ;
	for(int i = K - 1; i >= 1; i --) D[i] = min(D[i] , D[i + 1]) ;
	//for(int i = 1; i <= K; i ++) cout <<"choice"<<i<<":  "<< L[i] << " , " << R[i] << "   ;   " << U[i] << " " << D[i] << endl ; 
	S = 2 * (n + K) + 1 ;
	T = 2 * (n + K) + 2 ;
	for(int i = 1; i <= K; i ++) AddEdge(S , i , 1 , 0) ;
	for(int i = 1; i <= K; i ++) AddEdge(K + 2 * n + i , T , 1 , 0) ;
	for(int i = 1; i <= K; i ++)
		for(int j = 1; j <= n; j ++) {
			if(L[i] <= p[j].x && p[j].x <= R[i]) AddEdge(i , K + j , 1 , 0) ;
			if(U[i] <= p[j].y && p[j].y <= D[i]) AddEdge(K + n + j , K + 2 * n + i , 1 , 0) ;
		}
	for(int i = 1; i <= n; i ++) AddEdge(K + i , K + n + i , 1 , extra - p[i].v) ;
	Flow = 0 ; Cost = 0 ; 
	while(bfs()) {
		for(int i = 1; i <= T; i ++) cur[i] = head[i] ;
		Flow += dfs(S , 1e9) ;
	}
	Cost -= 1ll * extra * K ; Cost = -Cost ;
	if(Flow == K && Ans < Cost) Ans = Cost ; return ; 
}

int main() {
	n = gi() ;
	for(int i = 1; i <= n; i ++) p[i].x = gi() , p[i].y = gi() , p[i].v = gi() ;
	m = gi() ;
    for(int i = 1; i <= m; i ++) scanf("%c %d %d\n" , &q[i].t , &q[i].a , &q[i].b) ;
	for(int i = 1; i <= m; i ++) if(q[i].t == 'U') q[i].t = 'D' ; else if(q[i].t == 'D') q[i].t = 'U' ;
	//for(int i = 1; i <=m; i ++) cout << q[i].t << " ; a = " << q[i].a << " , b = " << q[i].b << endl ;
	Ans = 0 ;
	for(K = 1; K <= n; ++ K) solve() ;
	printf("%lld\n" , Ans) ;
	return 0 ; 
}


Measured memory_bytes: 768