#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
const int MX = 200005;
typedef pair<ll,P> Q;
typedef vector<Q> vq;

// Min cost flow
// !! Be care of double and INF !!
struct Mincost {
  typedef ll TC;
  typedef int TL;
  typedef pair<TC,int> TP;
  struct Edge {
    int to, nxt; TC co; TL lim;
    Edge(){}
    Edge(int to, int nxt, TC co, TL lim):to(to),nxt(nxt),co(co),lim(lim){}
  };
  int n;
  vi head, pre; vector<TC> dist;
  vector<Edge> e;
  Mincost(int n):n(n),head(n,-1) {}
  void add(int f, int t, TC c=0, TL l=1) {
    // cerr<<f<<" "<<t<<" "<<c<<" "<<l<<endl;
    e.pb(Edge(t,head[f],c,l)); head[f] = sz(e)-1;
    e.pb(Edge(f,head[t],-c,0)); head[t] = sz(e)-1;
  }
  void dijk(int sv){
    dist = vector<TC>(n,LINF); // INF !!
    pre = vi(n,-1);
    priority_queue<TP, vector<TP>, greater<TP>> q;
    int v; TC d;
    q.push(TP(0,sv));
    dist[sv] = 0;
    while (sz(q)) {
      d = q.top().fi; v = q.top().se; q.pop();
      if (dist[v] != d) continue;
      for (int i = head[v]; i != -1; i = e[i].nxt) {
        int u = e[i].to;
        if (e[i].lim && d+e[i].co < dist[u]) { // double !!
          dist[u] = d+e[i].co;
          pre[u] = i^1;
          q.push(TP(dist[u],u));
        }
      }
    }
  }
  TC solve(int sv, int tv, TL flow) {
    TC res = 0; TL f;
    while (flow>0) {
      dijk(sv);
      // cerr<<dist<<endl;
      if (dist[tv] == LINF) return -1; // (double) INF !!
      rep(i,n)for (int j = head[i]; j != -1; j = e[j].nxt) {
        e[j].co += dist[i] - dist[e[j].to];
      }
      f = flow;
      for (int i = tv; i != sv; i = e[pre[i]].to) f = min(f,e[pre[i]^1].lim);
      for (int i = tv; i != sv; i = e[pre[i]].to) {
        e[pre[i]^1].lim -= f, e[pre[i]].lim += f;
      }
      res += dist[tv]*flow; flow -= f;
    }
    return res;
  }
};
//

const int M = 102;
const ll B = 1001002003004005ll;

int main() {
  int n;
  scanf("%d",&n);
  vq ps;
  rep(i,n) {
    ll z;
    int x,y;
    scanf("%d%d%lld",&x,&y,&z);
    ps.pb(Q(z,P(x,y)));
  }
  vp dl, dr;
  vp dd, du;
  int q;
  scanf("%d",&q);
  rep(i,q) {
    char c;
    int x,y;
    scanf(" %c%d%d",&c,&x,&y);
    if (c == 'L') dl.pb(P(x,y));
    if (c == 'R') dr.pb(P(x-1,y));
    if (c == 'D') dd.pb(P(x,y));
    if (c == 'U') du.pb(P(x-1,y));
  }

  ll ans = 0;
  rrep(m,n) {
    // if (m != 4) continue; //
    int sv = M*2, tv = sv+1;
    Mincost g(tv+1);
    ll now = B*m;
    rep(i,n) {
      int x = ps[i].se.fi, y = ps[i].se.se;
      ll z = ps[i].fi;
      g.add(x,M+y,B-z,1);
    }
    bool ok = true;
    int flow = m;
    {
      vi l(M-1), r(M-1,m);
      for (P p : dl) {
        int x = p.fi, y = m-p.se;
        maxs(l[x],y);
      }
      for (P p : dr) {
        int x = p.fi, y = p.se;
        mins(r[x],y);
      }
      rep(i,M-1) {
        if (r[i] < l[i]) {
          ok = false;
          break;
        }
        if (l[i]) {
          g.add(sv,i+1,0,l[i]);
          g.add(i,tv,0,l[i]);
          flow += l[i];
        }
        g.add(i,i+1,0,r[i]-l[i]);
      }
    }
    if (!ok) continue;
    {
      vi l(M-1), r(M-1,m);
      for (P p : dd) {
        int x = p.fi, y = m-p.se;
        maxs(l[x],y);
      }
      for (P p : du) {
        int x = p.fi, y = p.se;
        mins(r[x],y);
      }
      rep(i,M-1) {
        if (r[i] < l[i]) {
          ok = false;
          break;
        }
        if (l[i]) {
          g.add(sv,M+i,0,l[i]);
          g.add(M+i+1,tv,0,l[i]);
          flow += l[i];
        }
        g.add(M+i+1,M+i,0,r[i]-l[i]);
      }
    }
    if (!ok) continue;
    g.add(sv,0,0,m);
    g.add(M,tv,0,m);
    ll res = g.solve(sv,tv,flow);
    // cerr<<res<<endl;
    if (res == -1) continue;
    now -= res;
    maxs(ans, now);
    // cerr<<m<<" "<<now<<endl;
    // rep(i,n) {
    //   cerr<<i<<" "<<g.e[i*2].lim<<endl;
    // }
  }

  cout<<ans<<endl;
  return 0;
}






















Measured memory_bytes: 256