#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <cstdint>
#include <unordered_set>
#include <unordered_map>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template <class T> void chmin(T &t, const T &f) { if (t > f) t = f; }
template <class T> void chmax(T &t, const T &f) { if (t < f) t = f; }



namespace MCF {
	#define MAXN 100010
	#define MAXM 100010
	#define wint int
	#define cint Int
	const wint wEPS = 0;
	const wint wINF = 1001001001;
	const cint cEPS = 0;
	const cint cINF = 1001001001001001001LL;
	int n, m, ptr[MAXN], next[MAXM], zu[MAXM];
	wint capa[MAXM], tof;
	cint cost[MAXM], toc, d[MAXN], pot[MAXN];
	int vis[MAXN], pree[MAXN];
	void init(int _n) {
		n = _n; m = 0; memset(ptr, ~0, n * sizeof(int));
	}
	void ae(int u, int v, wint w, cint c) {
		next[m] = ptr[u]; ptr[u] = m; zu[m] = v; capa[m] = w; cost[m] = +c; ++m;
		next[m] = ptr[v]; ptr[v] = m; zu[m] = u; capa[m] = 0; cost[m] = -c; ++m;
	}
	bool solve(int src, int ink, wint flo = wINF) {
		wint f;
		cint c, cc;
		int i, u, v;
		memset(pot, 0, n * sizeof(cint));
	//*
		for (bool cont = 1; cont; ) {
			cont = 0;
			for (u = 0; u < n; ++u) for (i = ptr[u]; ~i; i = next[i]) if (capa[i] > wEPS) {
				if (pot[zu[i]] > pot[u] + cost[i] + cEPS) {
					pot[zu[i]] = pot[u] + cost[i]; cont = 1;
				}
			}
		}
	//*/
		for (toc = 0, tof = 0; tof + wEPS < flo; ) {
			typedef pair<cint,int> node;
			priority_queue< node,vector<node>,greater<node> > q;
			for (u = 0; u < n; ++u) { d[u] = cINF; vis[u] = 0; }
			for (q.push(make_pair(d[src] = 0, src)); !q.empty(); ) {
				c = q.top().first; u = q.top().second; q.pop();
				if (vis[u]++) continue;
				for (i = ptr[u]; ~i; i = next[i]) if (capa[i] > wEPS) {
					cc = c + cost[i] + pot[u] - pot[v = zu[i]];
					if (d[v] > cc) { q.push(make_pair(d[v] = cc, v)); pree[v] = i; }
				}
			}
			if (!vis[ink]) return 0;
			f = flo - tof;
			for (v = ink; v != src; v = zu[i ^ 1]) { i = pree[v]; chmin(f, capa[i]); }
			for (v = ink; v != src; v = zu[i ^ 1]) { i = pree[v]; capa[i] -= f; capa[i ^ 1] += f; }
			tof += f;
			toc += f * (d[ink] - pot[src] + pot[ink]);
			for (u = 0; u < n; ++u) pot[u] += d[u];
		}
		return 1;
	}
}


const int LIM = 200;

int N;
vector<int> X, Y;
vector<Int> V;
int M;
vector<char> T;
vector<int> A, B;

int main() {
  for (; ~scanf("%d", &N); ) {
    X.resize(N);
    Y.resize(N);
    V.resize(N);
    for (int j = 0; j < N; ++j) {
      scanf("%d%d%lld", &X[j], &Y[j], &V[j]);
    }
    scanf("%d", &M);
    T.resize(M);
    A.resize(M);
    B.resize(M);
    for (int i = 0; i < M; ++i) {
      scanf(" %c%d%d", &T[i], &A[i], &B[i]);
    }
    
    Int ans = 0;
    for (int K = 1; K <= N; ++K) {
      cerr << "K = " << K << endl;
      vector<int> minX(K, -LIM);
      vector<int> maxX(K, +LIM);
      vector<int> minY(K, -LIM);
      vector<int> maxY(K, +LIM);
      for (int i = 0; i < M; ++i) {
        switch (T[i]) {
          case 'L': {
            // at most B[i] from x <= A[i]
            for (int u = B[i]; u < K; ++u) {
              chmax(minX[u], A[i] + 1);
            }
          } break;
          case 'R': {
            // at least K - B[i] from x <= A[i] - 1
            const int b = max(K - B[i], 0);
            for (int u = 0; u < b; ++u) {
              chmin(maxX[u], A[i] - 1);
            }
          } break;
          case 'D': {
            // at most B[i] from y <= A[i]
            for (int v = B[i]; v < K; ++v) {
              chmax(minY[v], A[i] + 1);
            }
          } break;
          case 'U': {
            // at least K - B[i] from y <= A[i] - 1
            const int b = max(K - B[i], 0);
            for (int v = 0; v < b; ++v) {
              chmin(maxY[v], A[i] - 1);
            }
          } break;
          default: assert(false);
        }
      }
      // cerr << "  minX = "; pv(minX.begin(), minX.end());
      // cerr << "  maxX = "; pv(maxX.begin(), maxX.end());
      // cerr << "  minY = "; pv(minY.begin(), minY.end());
      // cerr << "  maxY = "; pv(maxY.begin(), maxY.end());
      MCF::init(2 + K + K + N + N);
      for (int u = 0; u < K; ++u) {
        MCF::ae(0, 2 + u, 1, 0);
      }
      for (int v = 0; v < K; ++v) {
        MCF::ae(2 + K + v, 1, 1, 0);
      }
      for (int j = 0; j < N; ++j) {
        MCF::ae(2 + K + K + j, 2 + K + K + N + j, 1, -V[j]);
      }
      for (int u = 0; u < K; ++u) {
        for (int j = 0; j < N; ++j) {
          if (minX[u] <= X[j] && X[j] <= maxX[u]) {
            MCF::ae(2 + u, 2 + K + K + j, 1, 0);
          }
        }
      }
      for (int v = 0; v < K; ++v) {
        for (int j = 0; j < N; ++j) {
          if (minY[v] <= Y[j] && Y[j] <= maxY[v]) {
            MCF::ae(2 + K + K + N + j, 2 + K + v, 1, 0);
          }
        }
      }
      const bool status = MCF::solve(0, 1, K);
      cerr << "  status = " << status << endl;
      if (status) {
        chmax(ans, -MCF::toc);
      }
    }
    printf("%lld\n", ans);
  }
  return 0;
}


Measured memory_bytes: 2304