/**
 *    author:  tourist
 *    created: 19.01.2020 03:02:31       
**/
#include <bits/stdc++.h>

using namespace std;

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

template <typename T, typename C>
class mcmf {
 public:
  static constexpr T eps = (T) 1e-9;

  struct edge {
    int from;
    int to;
    T c;
    T f;
    C cost;
  };

  vector<vector<int>> g;
  vector<edge> edges;
  vector<C> d;
  vector<int> q;
  vector<bool> in_queue;
  vector<int> pe;
  int n;
  int st, fin;
  T flow;
  C cost;

  mcmf(int _n, int _st, int _fin) : n(_n), st(_st), fin(_fin) {
    assert(0 <= st && st < n && 0 <= fin && fin < n && st != fin);
    g.resize(n);
    d.resize(n);
    in_queue.resize(n);
    pe.resize(n);
    flow = 0;
    cost = 0;
  }

  void clear_flow() {
    for (const edge &e : edges) {
      e.f = 0;
    }
    flow = 0;
  }
   
  void add(int from, int to, T forward_cap, T backward_cap, C cost) {
    assert(0 <= from && from < n && 0 <= to && to < n);
    g[from].push_back((int) edges.size());
    edges.push_back({from, to, forward_cap, 0, cost});
    g[to].push_back((int) edges.size());
    edges.push_back({to, from, backward_cap, 0, -cost});
  }

  bool expath() {
    fill(d.begin(), d.end(), numeric_limits<C>::max());
    q.clear();
    q.push_back(st);
    d[st] = 0;
    in_queue[st] = true;
    int beg = 0;
    bool found = false;
    while (beg < (int) q.size()) {
      int i = q[beg++];
      if (i == fin) {
        found = true;
      }
      in_queue[i] = false;
      for (int id : g[i]) {
        const edge &e = edges[id];
        if (e.c - e.f > eps && d[i] + e.cost < d[e.to]) {
          d[e.to] = d[i] + e.cost;
          pe[e.to] = id;
          if (!in_queue[e.to]) {
            q.push_back(e.to);
            in_queue[e.to] = true;
          }
        }
      }
    }
    if (found) {
      T push = numeric_limits<T>::max();
      int v = fin;
      while (v != st) {
        const edge &e = edges[pe[v]];
        push = min(push, e.c - e.f);
        v = e.from;
      }
      v = fin;
      while (v != st) {
        edge &e = edges[pe[v]];
        e.f += push;
        edge &back = edges[pe[v] ^ 1];
        back.f -= push;
        v = e.from;
      }
      flow += push;
      cost += push * d[fin];
    }
    return found;
  }
   
  pair<T, C> max_flow_min_cost() {
    while (expath()) {}
    return {flow, cost};
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> x(n), y(n);
  vector<long long> v(n);
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> y[i] >> v[i];
  }
  int m;
  cin >> m;
  vector<char> t(m);
  vector<int> a(m), b(m);
  for (int i = 0; i < m; i++) {
    cin >> t[i] >> a[i] >> b[i];
  } 
  long long ans = 0;
  const int M = 100;
  for (int k = 1; k <= n; k++) {
    vector<int> lx(M + 1, 0), rx(M + 1, k);
    vector<int> ly(M + 1, 0), ry(M + 1, k);
    for (int i = 0; i < m; i++) {
      if (b[i] >= k) {
        continue;
      }
      if (t[i] == 'L') {
        lx[a[i]] = max(lx[a[i]], k - b[i]);
      }
      if (t[i] == 'D') {
        ry[a[i]] = min(ry[a[i]], b[i]);
      }
      if (t[i] == 'R') {
        rx[a[i] - 1] = min(rx[a[i] - 1], b[i]);
      }
      if (t[i] == 'U') {
        ly[a[i] - 1] = max(ly[a[i] - 1], k - b[i]);
      }
    }
    mcmf<int, long long> f(1 + (M + 2) + (M + 2) + 1, 0, 1 + (M + 2) + (M + 2));
    bool fail = false;
    int expected = 0;
    for (int i = 0; i <= M; i++) {
      if (lx[i] > rx[i]) {
        fail = true;
        break;
      }
      f.add(1 + i, 1 + i + 1, rx[i] - lx[i], 0, 0);
      f.add(f.st, 1 + i + 1, lx[i], 0, 0);
      f.add(1 + i, f.fin, lx[i], 0, 0);
      expected += lx[i];
    }
    for (int i = 0; i <= M; i++) {
      if (ly[i] > ry[i]) {
        fail = true;
        break;
      }
      f.add(1 + (M + 2) + i, 1 + (M + 2) + i + 1, ry[i] - ly[i], 0, 0);
      f.add(f.st, 1 + (M + 2) + i + 1, ly[i], 0, 0);
      f.add(1 + (M + 2) + i, f.fin, ly[i], 0, 0);
      expected += ly[i];
    }
    if (fail) {
      continue;
    }
    for (int i = 0; i < n; i++) {
      f.add(1 + x[i], 1 + (M + 2) + y[i], 1, 0, -v[i]);
    }
    f.add(f.st, 1, k, 0, 0);
    f.add(1 + (M + 2) + (M + 1), f.fin, k, 0, 0);
    expected += k;
    auto p = f.max_flow_min_cost();
    assert(p.first <= expected);
    if (p.first == expected) {
      ans = max(ans, -p.second);
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 384