#include <bits/stdc++.h>
#define inf 0x3f3f3f3f

using namespace std;

typedef long long ll;

struct Edge {
  int t,f,next;
  ll v;
  Edge() {}
  Edge(int a,int b,ll c,int d):t(a),f(b),v(c),next(d) {}
};

Edge e[1000000];
int head[410],vs,vt,tot=-1;

void addEdge(int x,int y,int z,ll v) {
  e[++tot]=Edge(y,z,v,head[x]);
  head[x]=tot;
  e[++tot]=Edge(x,0,-v,head[y]);
  head[y]=tot;
}

namespace Flow {

ll dis[410];
int cur[410];
bool in[410];
queue <int> q;

bool spfa() {
  while (!q.empty()) q.pop();
  memset(in,0,sizeof(in));
  for(int i=vs;i<=vt;i++) dis[i]=-1e18;
  dis[vs]=0;in[vs]=1;
  q.push(vs);
  while (!q.empty()) {
  	int x=q.front();q.pop();in[x]=0;
  	cur[x]=head[x];
  	for(int i=head[x];i!=-1;i=e[i].next)
  	  if (e[i].f&&dis[x]+e[i].v>dis[e[i].t]) {
  	  	  int u=e[i].t;
  	  	  dis[u]=dis[x]+e[i].v;
  	  	  if (!in[u]) {
  	  	  	    in[u]=1;
  	  	  	    q.push(u);
			  }
		}
  }
  return dis[vt]>-1e18;
}

int vis[410],cnt;

int dfs(int x,int a) {
  if (x==vt||!a) return a;
  vis[x]=cnt;
  int ans=0;
  for(int &i=cur[x];i!=-1;i=e[i].next)
    if (e[i].f&&vis[e[i].t]<cnt&&dis[x]+e[i].v==dis[e[i].t]) {
    	int u=e[i].t;
    	int f=dfs(u,min(a,e[i].f));
    	if (f) {
    		e[i].f-=f;
    		e[i^1].f+=f;
    		ans+=f;
    		a-=f;
    		if (!a) break;
		}
	}
  return ans;
}

ll msmf(int d) {
  int s1=0;
  ll s2=0;
  while (spfa()) {
  	int f;
    do {
    	cnt++;
    	f=dfs(vs,inf);
    	s1+=f;
    	s2+=f*dis[vt];
	} while (f);
  }
  return (s1>=d)?s2:0;
}

}

struct Data {
  int kind,x,y;
  ll v;
  Data() {}
  Data(int a,int b,int c,ll d):kind(a),x(b),y(c),v(d) {}
};

Data p[100],a[400];
int minx[400],maxx[400],miny[400],maxy[400];

ll solve(int n,int m,int k) {
  memset(head,255,sizeof(head));
  memset(minx,0,sizeof(minx));
  memset(maxx,0x3f,sizeof(maxx));
  memset(miny,0,sizeof(miny));
  memset(maxy,0x3f,sizeof(maxy));
  vs=0;vt=2*n+2*k+1;
  tot=-1;
  for(int i=1;i<=m;i++)
    if (a[i].kind==1) {
    	if (a[i].y<k) minx[a[i].y+1]=max(minx[a[i].y+1],a[i].x+1);
	}
	else if (a[i].kind==2) {
		if (a[i].y<k) maxx[k-a[i].y]=min(maxx[k-a[i].y],a[i].x-1);
	}
	else if (a[i].kind==3) {
    	if (a[i].y<k) miny[a[i].y+1]=max(miny[a[i].y+1],a[i].x+1);
	}
	else {
		if (a[i].y<k) maxy[k-a[i].y]=min(maxy[k-a[i].y],a[i].x-1);
	}
  for(int i=1;i<=k;i++) {
  	minx[i]=max(minx[i],minx[i-1]);
  	miny[i]=max(miny[i],miny[i-1]);
  }
  for(int i=k;i>0;i--) {
  	maxx[i]=min(maxx[i],maxx[i+1]);
  	maxy[i]=min(maxy[i],maxy[i+1]);
  }
  for(int i=1;i<=n;i++) addEdge(i,n+i,1,p[i].v);
  for(int i=1;i<=k;i++) {
  	addEdge(vs,2*n+i,1,0);
  	for(int j=1;j<=n;j++)
  	  if (p[j].x>=minx[i]&&p[j].x<=maxx[i]) addEdge(2*n+i,j,1,0);
  }
  for(int i=1;i<=k;i++) {
  	addEdge(2*n+k+i,vt,1,0);
  	for(int j=1;j<=n;j++)
  	  if (p[j].y>=miny[i]&&p[j].y<=maxy[i]) addEdge(n+j,2*n+k+i,1,0);
  }
  return Flow::msmf(k);
}

int main() {
  int n;
  scanf("%d",&n);
  for(int i=1;i<=n;i++) {
  	int x,y;
  	ll z;
  	scanf("%d%d%lld",&x,&y,&z);
  	p[i]=Data(0,x,y,z);
  }
  int m;
  scanf("%d",&m);
  for(int i=1;i<=m;i++) {
  	char str[5];
  	int x,y;
  	scanf("%s%d%d",str,&x,&y);
  	if (str[0]=='L') a[i]=Data(1,x,y,0);
  	else if (str[0]=='R') a[i]=Data(2,x,y,0);
  	else if (str[0]=='D') a[i]=Data(3,x,y,0);
  	else a[i]=Data(4,x,y,0);
  }
  ll ans=0;
  for(int i=1;i<=n;i++)
    ans=max(ans,solve(n,m,i));
  printf("%lld\n",ans);
  return 0;
}

Measured memory_bytes: 768