/**
 *    author:  tourist
 *    created: 16.03.2019 16:16:57       
**/
#include <bits/stdc++.h>

using namespace std;

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

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

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

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

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;
}

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

typedef long double ld;

const ld eps = 1e-8;

vector<ld> simplex(vector<vector<ld>> a) {
  int n = (int) a.size() - 1;
  int m = (int) a[0].size() - 1;
  vector<int> left(n + 1);
  vector<int> up(m + 1);
  iota(left.begin(), left.end(), m);
  iota(up.begin(), up.end(), 0);
  auto pivot = [&](int x, int y) {
    swap(left[x], up[y]);
    ld k = a[x][y];
    a[x][y] = 1;
    vector<int> pos;
    for (int j = 0; j <= m; j++) {
      a[x][j] /= k;
      if (fabs(a[x][j]) > eps) {
        pos.push_back(j);
      }
    }
    for (int i = 0; i <= n; i++) {
      if (fabs(a[i][y]) < eps || i == x) {
        continue;
      }
      k = a[i][y];
      a[i][y] = 0;
      for (int j : pos) {
        a[i][j] -= k * a[x][j];
      }
    }
  };
  while (1) {
    int x = -1;
    for (int i = 1; i <= n; i++) {
      if (a[i][0] < -eps && (x == -1 || a[i][0] < a[x][0])) {
        x = i;
      }
    }
    if (x == -1) {
      break;
    }
    int y = -1;
    for (int j = 1; j <= m; j++) {
      if (a[x][j] < -eps && (y == -1 || a[x][j] < a[x][y])) {
        y = j;
      }
    }
    if (y == -1) {
      return vector<ld>(); // infeasible
    }
    pivot(x, y);
  }
  while (1) {
    int y = -1;
    for (int j = 1; j <= m; j++) {
      if (a[0][j] > eps && (y == -1 || a[0][j] > a[0][y])) {
        y = j;
      }
    }
    if (y == -1) {
      break;
    }
    int x = -1;
    for (int i = 1; i <= n; i++) {
      if (a[i][y] > eps && (x == -1 || a[i][0] / a[i][y] < a[x][0] / a[x][y])) {
        x = i;
      }
    }
    if (x == -1) {
      return vector<ld>(); // unbounded
    }
    pivot(x, y);
  }
  vector<ld> ans(m + 1);
  for (int i = 1; i <= n; i++) {
    if (left[i] <= m) {
      ans[left[i]] = a[i][0];
    }
  }
  ans[0] = -a[0][0];
  return ans;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> x(n), y(n);
  vector<long long> z(n);
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> y[i] >> z[i];
  }
  vector<vector<ld>> mat;
  {
    vector<ld> row(n + 1);
    for (int i = 0; i < n; i++) {
      row[i + 1] = z[i];
    }
    mat.push_back(row);
  }
  {
    for (int i = 0; i < n; i++) {
      vector<ld> row(n + 1);
      row[0] = 1;
      row[i + 1] = 1;
      mat.push_back(row);
    }
  }
  int tt;
  cin >> tt;
  while (tt--) {
    string foo;
    int bar, baz;
    cin >> foo >> bar >> baz;
    vector<ld> row(n + 1);
    row[0] = baz;
    if (foo == "L") {
      for (int i = 0; i < n; i++) if (x[i] <= bar) row[i + 1] = 1;
    }
    if (foo == "R") {
      for (int i = 0; i < n; i++) if (x[i] >= bar) row[i + 1] = 1;
    }
    if (foo == "D") {
      for (int i = 0; i < n; i++) if (y[i] <= bar) row[i + 1] = 1;
    }
    if (foo == "U") {
      for (int i = 0; i < n; i++) if (y[i] >= bar) row[i + 1] = 1;
    }
    mat.push_back(row);
  }
  mat.emplace_back(n + 1, 1);
  mat.emplace_back(n + 1, -1);
  long long ans = 0;
  for (int cc = 1; cc <= n; cc++) {
    mat[(int) mat.size() - 2][0] = cc;
    mat[(int) mat.size() - 1][0] = -cc;
    vector<ld> ret = simplex(mat);
    if (!ret.empty()) {
      long long cur = 0;
      for (int i = 0; i < n; i++) {
        if (ret[i + 1] > 1 - eps) {
          cur += z[i];
        }
      }
      ans = max(ans, cur);
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 1024