#include <bits/stdc++.h>

using namespace std;

const int N = 666;

typedef int flow_t;
typedef long long cost_t;

const flow_t flow_inf = 1e9;
const cost_t cost_inf = 4e18;

namespace flow {
struct edge {
  int to, rev;
  flow_t cap;
  cost_t cost;

  edge(int _to, int _rev, flow_t _cap, cost_t _cost)
    : to(_to), rev(_rev), cap(_cap), cost(_cost) {}
};

vector<edge> g[N];
int ptr[N];
bool vis[N];
flow_t flow;
cost_t cost;
int n, sv, tv;
cost_t dist[N];

void init(int _n, int _sv, int _tv) {
  n = _n;
  sv = _sv;
  tv = _tv;
  for (int i = 0; i < n; i++) {
    g[i].clear();
  }
  flow = cost = 0;
}

void add(int from, int to, flow_t c, cost_t w) {
  g[from].push_back(edge(to, (int)g[to].size(), c, w));
  g[to].push_back(edge(from, (int)g[from].size() - 1, 0, -w));
}

bool expath() {
  for (int i = 0; i < n; i++) {
    vis[i] = false;
    dist[i] = cost_inf;
  }
  queue<int> que;
  que.push(sv);
  dist[sv] = 0;
  while (!que.empty()) {
    int v = que.front();
    que.pop();
    vis[v] = false;
    for (int i = 0; i < (int)g[v].size(); i++) {
      edge& e = g[v][i];
      if (e.cap && dist[e.to] > dist[v] + e.cost) {
        dist[e.to] = dist[v] + e.cost;
        if (!vis[e.to]) {
          vis[e.to] = true;
          que.push(e.to);
        }
      }
    }
  }
  return dist[tv] != cost_inf;
}

flow_t dfs(int v, flow_t r) {
  if (v == tv) {
    return r;
  }
  flow_t res = 0;
  vis[v] = true;
  for (int& i = ptr[v]; i < (int)g[v].size(); i++) {
    edge& e = g[v][i];
    if (e.cap && dist[e.to] == dist[v] + e.cost && !vis[e.to]) {
      flow_t d = dfs(e.to, min(r - res, e.cap));
      e.cap -= d;
      g[e.to][e.rev].cap += d;
      res += d;
      if (res == r) {
        vis[v] = false; 
        return r;
      }
    }
  }
  return res;
}

pair<flow_t, cost_t> exec(flow_t r) {
  while (expath()) {
    fill_n(ptr, n, 0);
    flow_t d = dfs(sv, r - flow);
    flow += d;
    cost += d * dist[tv];
  }
  return make_pair(flow, cost);
}
}

using flow::sv;
using flow::tv;
using flow::init;
using flow::exec;
using flow::add;

int n, m;
int L[N], R[N], D[N], U[N];
int low[N], high[N];
int x[N], y[N];
long long z[N];

long long solve(int take) {
  init(2 * (1 + take + n), 0, 1);
  for (int i = 0; i < n; i++) {
    add(2 + take + i, 2 + take + n + i, 1, -z[i]);
  }
  for (int i = 0; i < take; i++) {
    add(sv, 2 + i, 1, 0);
    add(2 + take + n + n + i, tv, 1, 0);
  }
  {
    for (int i = 0; i < take; i++) {
      low[i] = 0;
      high[i] = N;
    }
    for (int i = 0; i < N; i++) {
      if (L[i] < take) {
        low[L[i]] = max(low[L[i]], i + 1);
      }
      if (R[i] < take) {
        high[take - 1 - R[i]] = min(high[take - 1 - R[i]], i - 1);
      }
    }
    for (int i = 1; i < take; i++) {
      low[i] = max(low[i - 1], low[i]);
    }
    for (int i = take - 2; i >= 0; i--) {
      high[i] = min(high[i], high[i + 1]);
    }
    for (int i = 0; i < take; i++) {
      for (int j = 0; j < n; j++) {
        if (low[i] <= x[j] && x[j] <= high[i]) {
          add(2 + i, 2 + take + j, 1, 0);
        }
      }
    }
  }
  { 
    for (int i = 0; i < take; i++) {
      low[i] = 0;
      high[i] = N;
    }
    for (int i = 0; i < N; i++) {
      if (D[i] < take) {
        low[D[i]] = max(low[D[i]], i + 1);
      }
      if (U[i] < take) {
        high[take - 1 - U[i]] = min(high[take - 1 - U[i]], i - 1);
      }
    }
    for (int i = 1; i < take; i++) {
      low[i] = max(low[i - 1], low[i]);
    }
    for (int i = take - 2; i >= 0; i--) {
      high[i] = min(high[i], high[i + 1]);
    }
    for (int i = 0; i < take; i++) {
      for (int j = 0; j < n; j++) {
        if (low[i] <= y[j] && y[j] <= high[i]) {
          add(2 + take + n + j, 2 + take + n + n + i, 1, 0);
        }
      }
    }
  }
  return -exec(take).second;
}

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d %d %lld", &x[i], &y[i], &z[i]);
  }
  for (int i = 0; i < N; i++) {
    L[i] = n;
    R[i] = n;
    D[i] = n;
    U[i] = n;
  }
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    char type;
    int a, b;
    scanf(" %c %d %d", &type, &a, &b);
    if (type == 'L') L[a] = min(L[a], b);
    if (type == 'R') R[a] = min(R[a], b);
    if (type == 'D') D[a] = min(D[a], b);
    if (type == 'U') U[a] = min(U[a], b);
  }
  long long ans = 0;
  for (int take = 1; take <= n; take++) {
    ans = max(ans, solve(take));
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 1152