// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
#include<bitset>
#include<cstdlib>
// #include<deque>
// #include<multiset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;

// MinCostFlow(size, inf)
// MinCostFlow(size, inf, int& s, int& t)
// addEdge(from, to, capacity, cost, undirected = false)
// === build(s, t, flow) ===
// O(FE log V)
// return mincost
// return -1 if impossible
/// --- MinCostFlow {{{ ///
#include <cassert>
#include <queue>
#include <tuple>
#include <vector>
// with Dijkstra with Potential
struct MinCostFlow {
  struct Edge {
    int to;
    ll cap, cost;
    size_t rev;
  };
  int n;
  vector< vector< Edge > > graph;
  vector< ll > h; // potential
  vector< ll > dist;
  vector< int > prevv, preve;
  ll inf;
  MinCostFlow(int n, ll inf)
    : n(n), graph(n), h(n), dist(n), prevv(n), preve(n), inf(inf) {}
  MinCostFlow(int n, ll inf, int &s, int &t) : MinCostFlow(n + 2, inf) {
    s = n, t = n + 1;
  }
  void addEdge(int a, int b, ll cap, ll cost, int undirected = 0) {
    assert(cost >= 0);
    assert(0 <= a && a < n);
    assert(0 <= b && b < n);
    graph[a].emplace_back((Edge){b, cap, cost, graph[b].size()});
    graph[b].emplace_back((Edge){a, undirected ? cap : 0, -cost, graph[a].size() - 1});
  }
  ll build(int s, int t, ll f) {
    h.assign(n, 0);
    ll res = 0;
    while(f > 0) {
      dist.assign(n, inf);
      dist[s] = 0;
      // Dijkstra with potential
      using P = pair< ll, int >;
      priority_queue< P, vector< P >, greater< P > > pq;
      pq.emplace(0, s);
      while(pq.size()) {
        ll d;
        int v;
        tie(d, v) = pq.top();
        pq.pop();
        if(dist[v] < d) continue;
        for(size_t i = 0; i < graph[v].size(); i++) {
          Edge &edge = graph[v][i];
          ll nd = dist[v] + edge.cost + h[v] - h[edge.to];
          if(edge.cap > 0 && dist[edge.to] > nd) {
            dist[edge.to] = nd;
            pq.emplace(nd, edge.to);
            prevv[edge.to] = v;
            preve[edge.to] = i;
          }
        }
      }
      //
      if(dist[t] == inf) return -1;
      for(int v = 0; v < n; v++) h[v] += dist[v];

      ll d = f;
      for(int v = t; v != s; v = prevv[v]) {
        d = min(d, graph[prevv[v]][preve[v]].cap);
      }
      f -= d;
      res += d * h[t];
      for(int v = t; v != s; v = prevv[v]) {
        Edge &edge = graph[prevv[v]][preve[v]];
        edge.cap -= d;
        graph[v][edge.rev].cap += d;
      }
    }
    return res;
  }
};
/// }}}--- ///

ll inf = 1e18;

constexpr int N = 80, M = 320;

int n, m;
int x[N], y[N];
ll v[N];
char type[M];
int a[M], b[M];

int XL[N], XR[N];
int YL[N], YR[N];

// smin, smax {{{
template < class T, class U >
inline void smin(T &a, const U &b) {
  a = a < (T) b ? a : b;
}
template < class T, class U >
inline void smax(T &a, const U &b) {
  a = a < (T) b ? b : a;
}
// }}}

ll solve(int k) {
  if(k == 0) return 0;
  int s, t;
  MinCostFlow ecas(k + k + n + n, inf, s, t);
  for(int i = 0; i < k; i++) XL[i] = 0, XR[i] = 100;
  for(int i = 0; i < k; i++) YL[i] = 0, YR[i] = 100;
  for(int i = 0; i < m; i++) {
    if(b[i] >= k) continue;
    switch(type[i]) {
      case 'L':
        smax(XL[b[i]], a[i] + 1);
        break;
      case 'R':
        smin(XR[k - b[i] - 1], a[i] - 1);
        break;
      case 'D':
        smax(YL[b[i]], a[i] + 1);
        break;
      case 'U':
        smin(YR[k - b[i] - 1], a[i] - 1);
        break;
    }
  }
  for(int i = 0; i + 1 < k; i++) smax(XL[i+1], XL[i]), smax(YL[i+1] , YL[i]);
  for(int i = k - 2; i >= 0; i--) smin(XR[i], XR[i+1]), smin(YR[i] , YR[i+1]);

  ll bias = 1e15;

  for(int i = 0; i < k; i++) ecas.addEdge(s, i, 1, 0);
  for(int i = 0; i < k; i++) ecas.addEdge(k + i, t, 1, 0);
  for(int i = 0; i < n; i++) ecas.addEdge(k + k + i, k + k + n + i, 1, bias - v[i]);

  for(int i = 0; i < k; i++) {
    for(int j = 0; j < n; j++) {
      if(XL[i] <= x[j] && x[j] <= XR[i]) {
        ecas.addEdge(i, k + k + j, 1, 0);
      }
      if(YL[i] <= y[j] && y[j] <= YR[i]) {
        ecas.addEdge(k + k + n + j, k + i, 1, 0);
      }
    }
  }

  ll val = ecas.build(s, t, k);
  if(val == -1) return -1;

  val = -val + bias * k;
  return val;
}

// O(N^4 log N)
int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);

  cin >> n;
  for(int i = 0; i < n; i++) cin >> x[i] >> y[i] >> v[i];
  
  cin >> m;
  for(int i = 0; i < m; i++) cin >> type[i] >> a[i] >> b[i];

  ll ans = 0;

  int g = 0;
  for(int k = 1; k <= n; k++) {
    auto val = solve(k);
    // 単調性はないのか？
    assert(!g || val == -1);
    if(val != -1) smax(ans, val);
    else g = 1;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1288