#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
namespace mcmf {
struct Edge {
  int to, cap;
  ll cost;
  int rev;
};
vector<vector<Edge> > adj;
void clear(int S, int T) {
  adj.clear();
  adj.resize(T + 1);
}
void add(int u, int v, int cap, ll cost) {
  adj[u].push_back({v, cap, cost, adj[v].size()});
  adj[v].push_back({u, 0, -cost, adj[u].size() - 1});
}
ll solve(int S, int T) {
  ll ans = 0;
  while (true) {
    vector<pair<int, int> > from(T + 1);
    vector<ll> dist(T + 1, LLONG_MAX);
    vector<bool> in_que(T + 1);
    queue<int> que;
    que.push(S);
    dist[S] = 0;
    in_que[S] = true;
    while (!que.empty()) {
      int u = que.front();
      que.pop();
      for (int i = 0; i < adj[u].size(); i++) {
        auto e = adj[u][i];
        if (e.cap && dist[e.to] > dist[u] + e.cost) {
          dist[e.to] = dist[u] + e.cost;
          from[e.to] = {u, i};
          if (!in_que[e.to]) {
            in_que[e.to] = true;
            que.push(e.to);
          }
        }
      }
      in_que[u] = false;
    }
    if (dist[T] >= LLONG_MAX) {
      return ans;
    }
    int cap = INT_MAX;
    for (int u = T; u != S; u = from[u].first) {
      cap = min(cap, adj[from[u].first][from[u].second].cap);
    }
    ans += cap * dist[T];
    for (int u = T; u != S; u = from[u].first) {
      auto &e = adj[from[u].first][from[u].second];
      e.cap -= cap;
      adj[u][e.rev].cap += cap;
    }
  }
}
}
const int LIMIT = 100;
int main() {
  do {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
  } while (false);
  int n;
  cin >> n;
  vector<int> x(n), y(n);
  vector<ll> w(n);
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> y[i] >> w[i];
  }
  int m;
  cin >> m;
  vector<char> dir(m);
  vector<int> a(m), b(m);
  for (int i = 0; i < m; i++) {
    cin >> dir[i] >> a[i] >> b[i];
  }
  ll ans = 0;
  for (int k = 1; k <= n; k++) {
    vector<int> xl(k + 1), yl(k + 1), xr(k + 1, LIMIT), yr(k + 1, LIMIT);
    for (int i = 0; i < m; i++) {
      if (b[i] < k) {
        if (dir[i] == 'L') {
          xl[b[i] + 1] = max(xl[b[i] + 1], a[i] + 1);
        } else if (dir[i] == 'R') {
          xr[k - b[i]] = min(xr[k - b[i]], a[i] - 1);
        } else if (dir[i] == 'U') {
          yr[k - b[i]] = min(yr[k - b[i]], a[i] - 1);
        } else if (dir[i] == 'D') {
          yl[b[i] + 1] = max(yl[b[i] + 1], a[i] + 1);
        }
      }
    }
    for (int i = 2; i <= k; i++) {
      xl[i] = max(xl[i - 1], xl[i]);
      yl[i] = max(yl[i - 1], yl[i]);
    }
    for (int i = k - 1; i; i--) {
      xr[i] = min(xr[i], xr[i + 1]);
      yr[i] = min(yr[i], yr[i + 1]);
    }
    mcmf::clear(0, k * 2 + LIMIT * 2 + 1);
    for (int i = 1; i <= k; i++) {
      mcmf::add(0, i, 1, 0);
      for (int j = xl[i]; j <= xr[i]; j++) {
        mcmf::add(i, k * 2 + j, 1, 0);
      }
      for (int j = yl[i]; j <= yr[i]; j++) {
        mcmf::add(k * 2 + LIMIT + j, k + i, 1, 0);
      }
      mcmf::add(k + i, k * 2 + LIMIT * 2 + 1, 1, 0);
    }
    for (int i = 0; i < n; i++) {
      mcmf::add(k * 2 + x[i], k * 2 + LIMIT + y[i], 1, -w[i]);
    }
    ans = max(ans, -mcmf::solve(0, k * 2 + LIMIT * 2 + 1));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1236