#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int i = (a); i <= (b); ++ i)
#define rrp(i,a,b) for (int i = (a); i >= (b); -- i)
#define gc() getchar()
#define fir first
#define sec second
typedef pair<int,int> pii;
typedef double db;
typedef long long ll;
template <typename tp>
inline void read(tp& x) {
  x = 0; char tmp; bool key = 0;
  for (tmp = gc(); !isdigit(tmp); tmp = gc())
    key = (tmp == '-');
  for (; isdigit(tmp); tmp = gc()) 
    x = (x << 3) + (x << 1) + (tmp ^ '0');
  if (key) x = -x;
}
template <typename tp>
inline void ckmn(tp& x,tp y) {
  x = x < y ? x : y;
}
template <typename tp>
inline void ckmx(tp& x,tp y) {
  x = x < y ? y : x;
}

namespace flow {
  const int N = 500, M = 40000, INF = 0x3f3f3f3f;
  const ll LLINF = 1ll << 60;
  struct edge {
    int la,b,cap;
    ll co;
  } con[M];
  int tot=1,fir[N],st,en,n,inq[N],vis[N],flo;
  ll ans, dis[N], now;
  void add_edge(int from,int to,int capc,ll cos) {
    con[++tot] = (edge) {fir[from],to,capc,cos};
    fir[from] = tot;
    con[++tot] = (edge) {fir[to],from,0,-cos};
    fir[to] = tot;
  }
  int dfs(int pos,int imp) {
    if (pos == en || (!imp)) return ans += now * imp, flo += imp, imp;
    int ret = 0, tmp;
    vis[pos] = 1;
    for (int i = fir[pos] ; i ; i = con[i].la) {
      if (!con[i].co && !vis[con[i].b]) {
	tmp = dfs(con[i].b,min(imp,con[i].cap));
	con[i].cap -= tmp;
	con[i^1].cap += tmp;
	ret += tmp;
	imp -= tmp;
	if (!imp) break;
      }
    }
    return ret;
  }
  deque<int> q;
  void qpush(int pos) {
    inq[pos] = 1;
    if (q.empty()) q.push_back(pos);
    else {
      if (dis[pos] < dis[q.front()])
	q.push_front(pos);
      else q.push_back(pos);
    }
  }
  bool spfa() {
    while (!q.empty()) q.pop_back();
    rep (i, 1, n) dis[i] = LLINF;
    memset(inq,0,sizeof inq);
    dis[st] = 0;
    qpush(st);
    for (int pos ; !q.empty() ; ) {
      pos = q.front();
      q.pop_front();
      inq[pos] = 0;
      for (int i = fir[pos] ; i ; i = con[i].la) {
	if (con[i].cap && dis[con[i].b] > dis[pos] + con[i].co) {
	  dis[con[i].b] = dis[pos] + con[i].co;
	  if (!inq[con[i].b]) qpush(con[i].b);
	}
      }
    }
    if (dis[en] == LLINF) return 0;
    now += dis[en];
    for (int pos = 1 ; pos <= n ; ++ pos) {
      for (int i = fir[pos] ; i ; i = con[i].la)
	con[i].co += dis[pos] - dis[con[i].b];
    }
    return 1;
  }
  ll solve() {
    while (spfa()) {
      do memset(vis,0,sizeof vis);
      while (dfs(st, INF));
    }
    return ans;
  }
  void init() {
    tot = 1;
    memset(fir, 0, sizeof fir);
    now = ans = 0;
    st = en = n = 0;
    flo = 0;
  }
}

const int N = 120;
int liml[2][N], limr[2][N];
int n, m, px[N], py[N], sz = 100;
ll pv[N];
int lp[N], rp[N];
ll solve(int num) {
  flow::init();
  flow::n = 2 * n;
  rep (i, 1, n) flow::add_edge(i, i+n, 1, -pv[i]);
  flow::st = ++ flow::n, flow::en = ++ flow::n;
  rep (a, 0, 1) {
    rep (i, 1, num) lp[i] = 1, rp[i] = sz;
    rep (i, 1, sz) if (liml[a][i]+1 <= num)
      ckmx(lp[liml[a][i] + 1], i+1);
    rep (i, 1, sz) if (num > limr[a][i])
      ckmn(rp[num - limr[a][i]], i-1);
    rep (i, 2, num) lp[i] = max(lp[i-1], lp[i]);
    rrp (i, num-1, 1) rp[i] = min(rp[i+1], rp[i]);
    // rep (i, 1, num)
    //   printf("(%d,%d) ", lp[i], rp[i]);
    // puts("");
    if (a == 0) {
      rep (i, 1, num) {
	int id = ++ flow::n;
	flow::add_edge(flow::st, id, 1, 0);
	rep (j, 1, n) if (px[j] >= lp[i] && px[j] <= rp[i])
	  flow::add_edge(id, j, 1, 0);
      }
    } else {
      rep (i, 1, num) {
	int id = ++ flow::n;
	flow::add_edge(id, flow::en, 1, 0);
	rep (j, 1, n) if (py[j] >= lp[i] && py[j] <= rp[i])
	  flow::add_edge(j+n, id, 1, 0);
      }
    }
  }
  ll ret = -flow::solve();
  if (flow::flo == num) return ret;
  else return 0;
}
int main() {
  char str[3];
  int x,y;
  read(n);
  rep (i, 1, n)
    read(px[i]), read(py[i]), read(pv[i]);
  rep (a, 0, 1) rep (i, 1, sz)
    liml[a][i] = limr[a][i] = n;
  read(m);
  rep (i, 1, m) {
    scanf("%s", str);
    read(x), read(y);
    if (*str == 'L') {
      ckmn(liml[0][x], y);
    } else if (*str == 'R') {
      ckmn(limr[0][x], y);
    } else if (*str == 'D') {
      ckmn(liml[1][x], y);
    } else if (*str == 'U') {
      ckmn(limr[1][x], y);
    }
  }
  rep (a, 0, 1) rrp (i, sz-1, 1)
    liml[a][i] = min(liml[a][i], liml[a][i+1]);
  rep (a, 0, 1) rep (i, 2, sz)
    limr[a][i] = min(limr[a][i], limr[a][i-1]);
  ll ans = 0;
  rep (i, 1, n)
    ckmx(ans, solve(i));
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 768