#include <bits/stdc++.h>
#define ld double
#define ull unsigned long long
#define ll long long
#define pii pair<int, int>
#define iiii pair<int, pii>
#define mp make_pair
#define INF 1000000000
#define MOD 1000000007
#define rep(i, x) for(int (i) = 0; (i) < (x); (i)++)
inline int getint() {
	int x = 0, p = 1; char c = getchar();
	while (c <= 32) c = getchar();
	if (c == 45) p = -p, c = getchar();
	while (c > 32) x = x * 10 + c - 48, c = getchar();
	return x * p;
}
using namespace std;
//ruogu_alter
const int N = 405;
const int M = 85;
const int K = 325;
const int s = N - 1;
const int t = N - 2;
const int base0 = 100;
const int base1 = 200;
const ll inf = 2e18;
ll res;
struct edge {
  int to, val;
  ll cost;
  int rev;
};
int flow[N], pre[N], pree[N];
ll dis[N];
bool vis[N];
vector<edge> g[N];
int n, m;
int px[M], py[M], lx[M], rx[M], ly[M], ry[M];
ll v[M];
int a[K], b[K];
char op[K];
//
inline void addedge(int x, int y, int z, ll w) {
  g[x].emplace_back((edge){y, z, w, (int)g[y].size()});
  g[y].emplace_back((edge){x, 0, -w, (int)g[x].size() - 1});
}
bool spfa() {
  int st = 0;
  vector<int> qu; qu.emplace_back(s);
  rep(i, N) dis[i] = inf, flow[i] = INF;
  dis[s] = 0; vis[s] = true;
  while (st < qu.size()) {
    int u = qu[st++]; vis[u] = false;
    rep(i, g[u].size()) {
      edge &e = g[u][i];
      if (e.val && dis[e.to] > dis[u] + e.cost) {
        dis[e.to] = dis[u] + e.cost;
        flow[e.to] = min(flow[u], e.val);
        pre[e.to] = u;
        pree[e.to] = i;
        if (!vis[e.to]) {
          vis[e.to] = true;
          qu.emplace_back(e.to);
        }
      }
    }
  }
  return dis[t] < inf;
}
ll ek(int sum) {
  int f = 0; ll c = 0;
  while (spfa()) {
    int x = t;
    f += flow[t];
    c += 1ll * flow[t] * dis[t];
    while (x != s) {
      int y = pre[x], z = pree[x];
      g[y][z].val -= flow[t];
      g[x][g[y][z].rev].val += flow[t];
      x = y;
    }
  }
  if (f != sum) return 1;
  return c;
} 
void solve(int sum) {
  rep(i, sum) lx[i] = ly[i] = 1, rx[i] = ry[i] = 100;
  rep(j, m) {
    if (op[j] == 'L') for (int i = b[j]; i < sum; i++) lx[i] = max(lx[i], a[j] + 1);
    if (op[j] == 'D') for (int i = b[j]; i < sum; i++) ly[i] = max(ly[i], a[j] + 1);
    if (op[j] == 'R') rep(i, sum - b[j]) rx[i] = min(rx[i], a[j] - 1);
    if (op[j] == 'U') rep(i, sum - b[j]) ry[i] = min(ry[i], a[j] - 1);
  }
  rep(i, n) --lx[i], --ly[i], --rx[i], --ry[i];
  rep(i, n) if (lx[i] > rx[i] || ly[i] > ry[i]) return;
  rep(i, N) g[i].clear();
  rep(i, n) addedge(px[i], py[i] + base0, 1, -v[i]);
  rep(i, sum) {
    addedge(s, i + base1, 1, 0);
    for (int j = lx[i]; j <= rx[i]; j++) addedge(i + base1, j, 1, 0);
    for (int j = ly[i]; j <= ry[i]; j++) addedge(j + base0, i + base1 + sum, 1, 0);
    addedge(i + base1 + sum, t, 1, 0);
  }
  ll ans = ek(sum); 
  if (ans <= 0) res = max(res, -ans);
}
int main() {
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	n = getint(); 
  rep(i, n) {
    px[i] = getint() - 1, py[i] = getint() - 1;
    scanf("%lld", v + i);
  }
  m = getint();
  rep(i, m) {
    cin >> op[i]; a[i] = getint(); b[i] = getint();
  }
  for (int sum = 1; sum <= n; sum++) {
    solve(sum);
  }
  cout << res << endl;
  return 0;
}
